[fpc-pascal]Pointer Help

Anton Tichawa anton.tichawa at chello.at
Sun Feb 9 15:42:29 CET 2003


Hi,

> But getMem and reAllocMem allocate a number of bytes on the heap,
> wouldn't you have to free that number of bytes using freeMem(pointer, n)
> ?

No, Free Pascal keeps track of the allocated size for a pointer created with 
GetMem/ReallocMem. They need this information for heap management, so it's a 
good think to use this information to save one procedure parameter, which is 
a lot. If you want to determine the number of bytes to deallocate, you may do 
this by using:

  Function FreeMemSize(var p:pointer;Size:Longint):Longint;

Definition:
FreememSize
This function should release the memory pointed to by P. The argument Size is 
the expected size of the memory block pointed to by P. This should be 
disregarded, but can be used to check the behaviour of the program. 

I think with FreeMemSize you may corrput the heap, so be careful with it!

Anton.


>
> Btw, I'm using short strings, so I think it'll be ok for now...
>
> > Read the Manual - Free Pascal Programmer's Manual, Section 4.5, "Writing
> > Your Own Memory Manager" - because that's what you're actually doing.
> >
> > HTH
> >
> > Anton Tichawa.
> >
> >
> >
> > ----------
> >
> > "Adas Methode war, wie sich zeigen wird, Tagtr?ume in offenbar korrekte
> > Berechnungen einzuweben."
> >
> > Doris Langley Moore: Ada, Countess of Lovelace (London 1977).
> >
> > ----------
> >
> > Anton Tichawa
> > Volkertstrasse 19 / 20
> > A-1020 Wien
> > mobil: +43 664 52 07 907
> > email: anton.tichawa at chello.at
> >
> > ----------
> > _______________________________________________
> > fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

-- 

----------

"Adas Methode war, wie sich zeigen wird, Tagträume in offenbar korrekte 
Berechnungen einzuweben."

Doris Langley Moore: Ada, Countess of Lovelace (London 1977).

----------

Anton Tichawa
Volkertstrasse 19 / 20
A-1020 Wien
mobil: +43 664 52 07 907
email: anton.tichawa at chello.at

----------



More information about the fpc-pascal mailing list