Re: Dyn Arrays
- From: "Rudy Velthuis" <newsgroups@xxxxxxxxxxxx>
- Date: Sun, 24 Jun 2007 00:54:30 +0200
Alex Moore wrote:
Can I use SetLength to redimension a dynamic array.
For Instance can I do somthing like:
for I:= 1 to N do
begin
SetLength(MyArray, I);
Do Something with MyArray[I - 1];
end;
I am told that this leaks memory. Is that correct?
It won't leak memory, but redimensioning it (using SetLength) on each
iteration could very well fragment it, especially for a large N. It
could also become very slow, for a large N, since each time the array
must be copied over to a newly allocated array, by the RTL.
Have a look at my view on such practices:
http://blogs.teamb.com/rudyvelthuis/archive/2004/06/26/644.aspx
--
Rudy Velthuis http://rvelthuis.de
"There is no reason anyone would want a computer in their home."
-- Ken Olson, president, chairman and founder of Digital
Equipment Corp., 1977
.
- References:
- Dyn Arrays
- From: Alex Moore
- Dyn Arrays
- Prev by Date: Re: Dyn Arrays
- Next by Date: Re: Dyn Arrays
- Previous by thread: Re: Dyn Arrays
- Next by thread: Re: Dyn Arrays
- Index(es):