954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

SetLength information please

I have tried searching internet a little bit and found some useful information about the command

SetLength


I just wonder about a few things as I would like an array to "constantly" be redefined in size. When using it in one part of my program, it will be defined in one way. When using it in another part, it will be defined in another way.
Ultimately, in my program, this may be done thousands of times.
The reason why I want to use one variable for this is simply the enormous memory needed and lack of ability to make reuseable code if defining many different arrays.

I just wonder if it is "ok" to define the length of an array like this many times.
Should I somehow free the allocated memory before re-defining the length of the "new" array?

Any information about this issue would be greatly appreciated.

Morten Brendefu
Light Poster
44 posts since Mar 2011
Reputation Points: 38
Solved Threads: 2
 

Looks for me that you are using global variables when you should use local so that the memory would only be recerved until need for values disapears.

pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

The whole point of having this one Global variable is exactly that. It have to be global so that a lot of procedures and functions can access it.
I am using this in combination with SQL and Interbase. If using only a local setup for this, it will lead to a lot of extra cpucycles and code for loading data into the local variables on demand.
At least I try to restrict my program to use One global array like this instead of a bunch of arrays :-)

I have found many examples on internet where an array is redefined to a bigger size, just no information what so ever about freeing memory afterwards.
In a way I just suppose this is not needed. I just hope there are no caveeats with this approach :D

Regards.
M.

Morten Brendefu
Light Poster
44 posts since Mar 2011
Reputation Points: 38
Solved Threads: 2
 

SetLength does the appropriate memory management for you, if you are not using objects in it.

Why not use a TList instead of constantly resizing an array.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 874
 

Simply because I want very easy access.
The whole point is to extend a listbox, combobox, checklistbox or similar with a number of extra fields not visible to the user of software.
I know I can use different type of ready made boxes or grids too, but I dislike the constant conversion between text and numbers too :D

If there was an easy way to add several integers to every line in a listbox, then I would use it, but I do not see any easy implementation of this.
I would like the ability to sort the listbox and have extra numbers to follow.
But also be able to choose a column of extra numbers and do sorting there.
I just demand too much out of a simple box :-)

Morten Brendefu
Light Poster
44 posts since Mar 2011
Reputation Points: 38
Solved Threads: 2
 

Thank you for the answer about memory management by the way :-)
Best regards.
Morten.

Morten Brendefu
Light Poster
44 posts since Mar 2011
Reputation Points: 38
Solved Threads: 2
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: