[fpc-pascal] How are Assigned, Free, Nil and Destroy related?

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Sat Oct 22 11:01:10 CEST 2011


Felipe Monteiro de Carvalho wrote:

> Free is how you release the memory allocated for a object. Free calls
> Destroy. Never call Destroy manually. When you implement the
> destructor you always implement Destroy, never change Free.

A number of years ago, Matthew Jones's wife looked over his shoulder and 
caught him using Create and Destroy. "Bit violent, isn't it?" When he 
told the story somebody else pointed out that he should be using Create 
and Free, I find this anecdote makes it easy to remember.

> Nil is not a routine, it is a value, it means that the object is
> empty, it does not exist / is not allocated. Nil in existing
> implementations that I know is represented by the value zero.

I've once seen a compiler using a non-zero value, I think it was the 
first Logitech protected-mode Modula-2 and it used ffff:0000. Apart from 
that I think that C specifies that nil has a bit pattern of all zeros, 
and anything with even the slightest interest in compatibility sticks to 
this as a convention.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list