[fpc-devel] an observation about GetMem

Peter Popov ppopov at tamu.edu
Thu Sep 4 18:32:22 CEST 2008


As I was porting things from delphi to fp today I noticed the following  
difference:

Delphi (2,5)       : GetMem(p, 0) will set p to nil.
FPC (2.2.2, 2.3.1) : GetMem(p, 0) will assign something to p

Clearly, the above calls are bad karma (which I have been practicing,  
apparently). Delphi's help does not say what GetMem should do when the  
size is 0 (realloc does). On the other hand, assigning something is a bad  
idea too, as it suggests at least Size(pointer) amount of storage, unless  
that memory spot is somehow marked as "empty", etc.

Do you think this should be reported as a feature, or should the  
definition of GetMem be changed to cover this case. Note that it is  
desirable to specify explictly what GetMem(p, 0) should do, since one can  
in principle provide a separate heap manager. Therefore, behavior of  
use-supplied getmem should be unniform.

Peter Popov



More information about the fpc-devel mailing list