[fpc-pascal] New/Dispose vs GetMem/FreeMem

Florian Klaempfl florian at freepascal.org
Thu Oct 15 11:01:16 CEST 2009


Graeme Geldenhuys schrieb:
> Hi,
> 
> Which of these should I use in new projects? I read somewhere that
> GetMem/FreeMem is actually compatibility methods from Turbo Pascal
> days, yet I have seen lots of new code that uses it, so I guess it's
> still ok to use?

GetMem/FreeMem are lower level than new/dispose. Use New/Dispose as much
as possible.

> 
> I have various complex structured types and pointers to those types.
> Will New() and Dispose() automatically know what size to allocated and
> deallocate, seeing that it doesn't have a Size parameter?

Yes. It initializes/finalizes even automated types what Get/FreeMem
doesn't do.



More information about the fpc-pascal mailing list