Turiya 01-23-2008, 03:33 AM Simply put:
Is there a way to copy an entire array into a bigger array?
eg: CopyArray strArray, strBigArray(6,19)
To explain:
Is there a way to copy all elements of an array into another, bigger, multi-dimensional array. To explain: I want to move every element in Array1 to BigArray2(7,16) so that I can access Array1(6) using BigArray2(7,16,6). Can this be done?
Currently coded as:
For lCheck = 0 To UBound(baImage)
baaaLastImg(lXLoop, lYLoop, lCheck) = baImage(lCheck)
Next lCheck
the master 01-23-2008, 03:43 AM I seem to remember trying this myself once and i think you can just put 1 into the other but it hasnt always worked for me.
I think you will need some kind of API like copy memory although the easiest solution would be to put your data in the big array from the start.
Turiya 01-23-2008, 04:04 AM Well, I've solved some of my problem. Turns out CopyMemory will copy an array, now I just need to get it to copy a monodimensional array (eg. Dim Array1(1) as Byte) into a 3 dimensional array (eg. Dim Array2(1,1,1) as Byte). Any ideas from the masters?
Turiya 01-23-2008, 04:10 AM Here's the progression.
I get a bunch of sets of data. I send them out over winsock. I get a bunch of new sets of data. If they are different, I send them out over winsock.
Due to the massive amounts of data, I don't want to send EVERYTHING over winsock if it doesn't need to be updated. So I created a big array to store the last sent data. I copy the data as it is sent out into the big array, then, next time the same set of data is sent out, I check the set against the previous data (stored in the big array). Problem is, copying and checking is very slow, and I want to speed it up. Hence the two threads.
DougT 01-23-2008, 04:13 AM CopyMemory will do the trick, but you have to remember how elements are stored in memory. Here's a quick example
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Command1_Click()
Dim lngArray(0 To 9) As Long
Dim lngArray1(0 To 1, 0 To 4) As Long
Dim intI As Integer
Dim intJ As Integer
For intI = LBound(lngArray) To UBound(lngArray)
lngArray(intI) = intI
Debug.Print lngArray(intI),
Next intI
Debug.Print
CopyMemory lngArray1(0, 0), lngArray(0), 10 * 4
For intI = 0 To 4
For intJ = 0 To 1
Debug.Print "Element(" & CStr(intJ) & "," & CStr(intI) & ")" & lngArray1(intJ, intI)
Next intJ
Next intI
End Sub
the master 01-23-2008, 04:15 AM If you have copymemory working then why not use a UDT?
Instead of declaring a multidimensional array you could try this
private type myudt
subArray() as byte
end type
dim mainArray() as myudt
You actually have single dimension arrays but you can store data in the same way as a multidimensional array
DougT 01-23-2008, 04:28 AM Here's a 3D example using CopyMemory
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Command1_Click()
Dim lngArray(0 To 26) As Long
Dim lngArray1(0 To 2, 0 To 2, 0 To 2) As Long
Dim intI As Integer
Dim intJ As Integer
Dim intK As Integer
For intI = LBound(lngArray) To UBound(lngArray)
lngArray(intI) = intI
Debug.Print lngArray(intI),
Next intI
Debug.Print
CopyMemory lngArray1(0, 0, 0), lngArray(0), (UBound(lngArray) + 1) * 4
For intI = 0 To 2
For intJ = 0 To 2
For intK = 0 To 2
Debug.Print "Element(" & CStr(intK) & "," & CStr(intJ) & "," & CStr(intI) & ")" & lngArray1(intK, intJ, intI)
Next intK
Next intJ
Next intI
End Sub
Turiya 01-23-2008, 04:29 AM I figured it out myself, thru trial and error. But thanks anyways.
Turns out the problem I was having WAS with how variables are stored in an array. When I called CopyMemory like this:
Dim ba1() As Byte
Dim ba2() As Byte
ReDim ba1(2)
ReDim ba2(2, 2, 2)
ba1(0) = 0
ba1(1) = 16
ba1(2) = 32
CopyMemory ba2(1, 1, 0), ba1(0), 3
I expected to find that ba2(1,1,0) = 0, ba2(1,1,1) = 16, and ba2(1,1,2) = 32.
What I found out. Was that I was wrong.
as it turns out, CopyMemory works from the other side. so:
CopyMemory ba2(0, 1, 1), ba1(0), 3
makes ba2(0,1,1) = 0, ba2(1,1,1) = 16, and ba2(2,1,1) = 32.
I hereby triumph over VB's lack of low level memory functions. :)
Turiya 01-23-2008, 04:31 AM Very cool example DougT. The 3D one. You just sneak values right in there! It's like...being a ninja. Only...nerdier.
DougT 01-23-2008, 04:34 AM I expected to find that ba2(1,1,0) = 0, ba2(1,1,1) = 16, and ba2(1,1,2) = 32.
What I found out. Was that I was wrong.
Vb cannot be held responsible for your expectations. :chuckle:
as it turns out, CopyMemory works from the other side.
CopyMemory just copies sequentially from one location to another. Arrays are stored in sequential order from the last dimenson through to the first dimension. (as my examples demonstrate)
VB's lack of low level memory functions? How much lower do you want to go? :D
Turiya 01-23-2008, 04:41 AM Assembly! :p
Turiya 01-23-2008, 04:44 AM PS, if you're on the solving Warpath, please help with my other thread.
|