[fpc-pascal] memory allocation of dynamic array
Michael Van Canneyt
michael at freepascal.org
Sun Jan 2 02:23:53 CET 2005
On Sun, 23 Sep 2007, Marc Santhoff wrote:
> a while ago I asked if I can assume the memory held by dynamic arrays is
> allocated in one contiguous block.
> The answer was sth. like "No, never!".
> I wrote a small testing programm using SetLenght() on an array multiple
> times using a bigger size every time and comparing the addresses of the
> allocated elements.
> I wasn't able to provoke getting something else than sizeof(integer),
> which is the base type of that array.
> My question:
> In which cases will it happen that the memory of a dynamic array is
> fragmented into multiple non-contiguous blocks?
Currently this is not done, but you should not assume that this
behaviour is intentional. If the compiler people decide to change
the implementation (for instance for efficiency reasons), your
code will break.
More information about the fpc-pascal