[fpc-pascal] replacement of MARK and RELEASE function in free pascal

Karoly Balogh (Charlie/SGR) charlie at scenergy.dfmk.hu
Thu Jun 19 17:02:55 CEST 2014


On Thu, 19 Jun 2014, johanns at nacs.net wrote:

> I seem to remember being warned in the old days of Turbo Pascal not mix use of
> getmem()/freemem() and new()/dispose() within a program, due to differences in
> the memory allocation strategies.  Are there still any compatibility or
> efficiency/performance issues with alternating between these two families, or
> can the most simple or appropriate call be used interchangeably?  In other
> words, now that objects are so much more prevalent in Pascal code, should
> getmem() and freemem() be avoided?

Not in Free Pascal at least. In FPC New/Dispose are inline functions
generated by the compiler (because they need to do other things aside the
memory allocation), but the memory handling part internally just wraps to
GetMem and FreeMem.

(See pinline.pas, new_dispose_statement() in the compiler sources for all
the dirty details.)

However, while mixing New/Dispose with GetMem/FreeMem in the same code
shouldn't have any ill. effects, you still should *not* mix New/Dispose on
the *same* pointer I think. (Eg. allocate with New, but free with
FreeMem, and so on.)


More information about the fpc-pascal mailing list