View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default What does Redim Preserve do in term of memory

"Chip Pearson" wrote in message:
I believe Redim Preserve creates a new array with the specified bounds and
then does an element-by-element copy from the old array to the new array,
and then finally destroys the original array.


My take is very slightly different in one small respect. From what I can
make out if Redim Preserve is used to increase the size of the last
dimension, exactly as Chip describes occurs. However if ReDim Preserve is
used to decrease the size then the lower portion of the array remains as
exactly was, in terms of memory address, and the upper portion freed from
memory.

On that basis, wherever viable I start with an oversized array and Redim
Preserve 'down' to required size when done, when the initial size is not
known say at start of some loop (along the lines both Chip and Jim
describe).

Regards,
Peter T