Re:FPC: ^longint type, memory question
In article
<Pine.LNX.4.21.0001272148400.280-100...@machine.iverlek.kotnet.org>,
Quote
Walied Othman <Walied.Oth...@Student.KULeuven.ac.be> wrote:
> suppose a variable V is declared as ^longint, and I perform a getmem twice
> on V, what happens to the memory that is reserved for V with the first
> getmem after the second getmem, is it freed or will you, when performing a
> lot of getmems, eventually get a stack overflow?
You'll get a memory leak (which won't cause a stack overflow, but it
will cause an out-of-memory error or an enormous swap file after a
while), just as you would get one when doing twice a getmem for another
pointer variable without freemem'ing first.
If you get fpc versino 0.99.14 (just released), you can use reallocmem
instead, that will save you the hassle of freemem/getmem every time.
Note that in FPC, you don't have to specify the size when doing a
freemem, so
var l: ^longint;
begin
getmem(l,10000);
reallocmem(l,15000);
freemem(l);
end.
is completely legal and will free the correct size.
To everyone: the reason version 0.99.14 of FPC hasn't been widely
annoucned, is because we plan on releasing version 1.0 in a couple of
weeks, so you can save yourself the hassle of downloading it two times.
Jonas