Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-10

New/Dispose vs GetMem/FreeMem

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

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?

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?

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/
Florian Klaempfl
to Graeme Geldenhuys
Show quoted text 6 lines
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.

Alain Michaud
to Florian Klaempfl

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

Alain Michaud

Florian Klaempfl wrote 20 lines
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 - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Marco van de Voort
to Alain Michaud

In our previous episode, Alain Michaud said:

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

FPC code, but you can change to "malloc", by using unit cmem (only on *nix)