|
-
Oct 18th, 2000, 02:15 PM
#1
Hi all.
Does anyone know how I can copy a section of an array to another array without using loop code to copy each value one at a time, which is slow. Fox already proposed I use copymemory, but the values in the arrays are not of fixed size, so I can't use it.
Any other suggestion?
Thanks!
-
Oct 18th, 2000, 08:34 PM
#2
Monday Morning Lunatic
Why aren't they of fixed size? Are they Strings?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 18th, 2000, 09:06 PM
#3
Hyperactive Member
Yes they are
The contents of a VB array are always the same size. That is the whole point of an array...
If you have an array of Variants which is the only thing I can think of that would confuse someone, then these are all 16 bytes in length. Arrays of user defined types will have a particular size as well (depends on what the members are of course) and arrays of objects are 4 bytes each.
Sure, part of the variant is a pointer to some actual data (or the data is already there in that 16 bytes), which is why I think you say "the values in the arrays are not of fixed size". I just wanted to make sure that anyone else reading your post didn't go an believe that 
What you are wanting to do is to iterate through an array and copy any data that the array might point to. In this case, CopyMemory won't help you as you already stated. I can see no easier method than using a loop.
If you give an example of the problem form start to finish, someone might be able to propose a solution. Looking at only the end of the problem is not enough to let us give any useful advice 
Regards
-
Oct 18th, 2000, 11:33 PM
#4
Its an array of UDT's
Its an array of UDT's, which can sometimes have strings or worst, arrays not having a fixed content of elements (the number of element in the array is not the same from one element to the other).
Ex:
type element_1
a as integer
table_1() as integer
end type
The number of elements in table_1 can change....
So, any idea?...
Thanks.
-
Oct 19th, 2000, 02:50 AM
#5
Hyperactive Member
Array of UDT
Well each UDT element will have the same length as the rest. Some of the members of the array may well be pointers to more data (for example your arrays that are UDT members)
You cannot really determine where in memory those pomters will point to ahead of time. So you will not really be able to block copy array elements. If you did use CopyMemory, you would copy the element data including the member that is a pointer to an array, and then you will be able to access that array member like normal. However, updates to the original array member will update the copy and vice versa. I doubt you would really want that so you are back to square one.
I believe you need to iterate through your array OR you need to change the way you store data. Before you start thinking about that though, you have to ask yourself whether the minor inconvenience of having to iterate through the elements is worse than the hassle it will be to arrange your data differently. (That is assuming that it is feasible to arrange the data another way more useful for CopyMemory to deal with).
I hope you find another way to do what you want - because I would be interested in learning the technique for sure 
Regards
-
Oct 19th, 2000, 04:54 AM
#6
PowerPoster
Erm, why don't you just use the = ???
Code:
Type element_1
A as integer
Table_1() as integer
End Type
Dim elements(3) as element_1
'No problem using this:
elements(0) = elements(1)
elements(1) = elements(2)
-
Oct 19th, 2000, 07:58 AM
#7
I'm looking for something faster...
Well fox, I precisely wanted to avoid going through each and every value of the array (using some sort of loop code like do-while or for-next). I though there would be a faster command where I could say, for example,
elements_a(3 to 45) = elements_b(1 to 42).
I wanted to use the command in a sorting procedure.
But then if such command does not exist, well... lets loop!
-
Oct 19th, 2000, 09:28 AM
#8
PowerPoster
Yeah, wouldn't know another way, too...
-
Oct 19th, 2000, 09:35 AM
#9
Well, thanks anyway..
Ok, well thanks anyway guys.
One day I hope, I will be able to help you as much as you do for me! 
P.S.: Fox, thanks for all the samples on your site. I downloaded almost everything!
-
Oct 19th, 2000, 11:19 AM
#10
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|