Re: Arrays
- From: Lorin <Lorin@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 23 Sep 2008 08:41:01 -0700
As long a pointers are properly and timely restored/maintined, no memory
leaks occur.
I have been running the code in both a test harness and in a real
applications with no problems.
"Bill McCarthy" wrote:
Hi Bob,.
If you are careful, and the data are simple value types like double or long,
then you can use copy memory to move the blocks around as a mutli
dimensional array is just a continuous block of memory. You could then
adjust the array dimensions via the safe array, but you are probably going
to leak memory doing that.
alternatively you could use jagged arrays, although the support for them in
VB6 is limited a bit, e.g:
Dim columns() As Variant
Dim row() As Long
Dim i As Long, j As Long
ReDim columns(0 To 5)
For i = 0 To 5
ReDim row(0 To 10)
columns(i) = row
Next i
For i = 0 To UBound(columns)
For j = 0 To UBound(columns(i))
columns(i)(j) = i * 10000 + j
Next j
Next i
For i = 0 To UBound(columns)
For j = 0 To UBound(columns(i))
Debug.Print i, j, columns(i)(j)
Next j
Next i
ReDim Preserve columns(0 To 3)
For i = 0 To UBound(columns)
row = columns(i)
ReDim Preserve row(0 To 5)
columns(i) = row
Next i
For i = 0 To UBound(columns)
For j = 0 To UBound(columns(i))
Debug.Print i, j, columns(i)(j)
Next j
Next i
Note that to re-dimension a row you need to copy it you, change it's size
and copy it back in
The fastest alternative is likely to be to create a new array of the correct
size and copy the data over to it.
"Bob" <someonw@xxxxxx> wrote in message
news:%232eP%238OHJHA.3960@xxxxxxxxxxxxxxxxxxxxxxx
Hi Everyone:
I have a 2D array A(n,n). At times, I may need to decrease the size of
the array by one, like
Redim B(0 to n-1,0 to n-1)
for i=1 to n
for j=1 to n
B(i-1,j-1)=A(i,j)
next j
next i
Is this the easiest and fastest way to achieve this, or is there a better
way. Thanks for your help.
Bob
- Follow-Ups:
- Re: Arrays
- From: Bill McCarthy
- Re: Arrays
- References:
- Arrays
- From: Bob
- Re: Arrays
- From: Bill McCarthy
- Arrays
- Prev by Date: Re: Runs over Vista or XP?
- Next by Date: Re: Arrays
- Previous by thread: Re: Arrays
- Next by thread: Re: Arrays
- Index(es):
Relevant Pages
|