[fpc-devel] an observation about GetMem
    Peter Vreman 
    peter at freepascal.org
       
    Fri Sep  5 10:43:20 CEST 2008
    
    
  
> Peter Popov wrote:
>> Well, if it points to something, then there is space, isn't it? Unless
>> it is clearly mentioned in the documentation that GetMem(p,0) results in
>
> You get a pointer to some place where you may store 0 bytes, so nothing :-).
>
> This can be useful because otherwise you may think the allocation failed
> if you get nil back. (And you've disabled heap exception).
In FPC it is done by design. If 0 bytes are asked we allocate at least the minimum alignment to
get a valid pointer. This is done for compatibility with TP7.0 that returns the value of heapptr
which is also a valid pointer.
Peter
    
    
More information about the fpc-devel
mailing list