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

Alain Michaud Alain.Michaud at nrc-cnrc.gc.ca
Fri Oct 16 21:12:30 CEST 2009


Are they based on the C library "maloc" or entirely genuine FPC code?

Alain Michaud


Florian Klaempfl wrote:
> 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.
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal



More information about the fpc-pascal mailing list