Re: Arrays



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


.



Relevant Pages

  • Re: Framework 2.0 array redim unsatisfactory performance
    ... I am not talking about "array redim" anymore. ... ReDim simply allocates a new ... but I do not even attempt to test its memory ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Arrays
    ... 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. ... Dim columns() As Variant ... ReDim columns ...
    (microsoft.public.vb.general.discussion)
  • RE: Arrays/Redim/Help!
    ... The rule with multi dim arrays is that you can only redim the last element in ... ReDim ary ... It has to do with the way memory is stored. ... A multi dim array, like any ...
    (microsoft.public.excel.programming)
  • Re: Fexible Arrays
    ... How do you make a flexible array. ... redim preserve arMyArray ... releases memory used before (it may reuse the same memory, ...
    (microsoft.public.vb.general.discussion)
  • Re: Memory Leak Issue
    ... EmptClearto pack the array. ... to detect memory leaks like described above, ... If you are talking about leaks as described above, most leak detectors miss ...
    (microsoft.public.vc.debugger)