Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic array help please

Status
Not open for further replies.

rsballard

Technical User
Oct 1, 2002
16
US
I have a bunch of files to process, each will have a different number of items to deal with.

define some dynamic arrays
var array1, array2, array3: array of double;

open the first file and scan through it to determine how many data items to process

allocate memory for each array
SetLength(array1,count);
SetLength(array2,count);
SetLength(array3,count);

do my thing and read and process the data for one file...

Now, my question is, to zero/release those arrays in preparation for the next file, is it corrrect to free the space used for those arrays like this:

SetLength(array1,0);
SetLength(array2,0);
SetLength(array3,0);

and then get ready to do it all over again for the next file? If not, what is the best technique to release memory before re-allocating to the new, most likely different, size for the next file? And how about releasing all memory used at the end of the job upon exit?

Thanks
Bob
 
Setting lengh to 0 will do the job. Also you can set array variable to nil or call to Finalize procedure.

--- markus
 
It's not neccessary to release it anyway--next time you set the length it gets released. Setting the length to zero does have one benefit, though--the array is zeroed.
 
Thanks, I'm initializing for each new file after counting lines and the resetting to 0 when through. Seems to work well.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top