Re: [fpc-devel] an observation about GetMem

2008-09-08 Thread petr . kristan
On Sat, Sep 06, 2008 at 11:25:19AM +0100, Jonas Maebe wrote: On 05 Sep 2008, at 17:25, Peter Popov wrote: 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

Re: [fpc-devel] an observation about GetMem

2008-09-08 Thread Peter Vreman
On Sat, Sep 06, 2008 at 11:25:19AM +0100, Jonas Maebe wrote: On 05 Sep 2008, at 17:25, Peter Popov wrote: 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

Re: [fpc-devel] an observation about GetMem

2008-09-06 Thread Jonas Maebe
On 05 Sep 2008, at 17:25, Peter Popov wrote: 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. Thanks for the

Re: [fpc-devel] an observation about GetMem

2008-09-05 Thread Michael Schnell
Peter Popov wrote: 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 Should it be forbidden do allocate a buffer of size 0 and reallocate it

Re: [fpc-devel] an observation about GetMem

2008-09-05 Thread Micha Nelissen
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

Re: [fpc-devel] an observation about GetMem

2008-09-05 Thread Peter Vreman
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

Re: [fpc-devel] an observation about GetMem

2008-09-05 Thread Peter Popov
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). you have a point In FPC it is done by design. If 0 bytes are asked we allocate

[fpc-devel] an observation about GetMem

2008-09-04 Thread Peter Popov
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

Re: [fpc-devel] an observation about GetMem

2008-09-04 Thread Micha Nelissen
Peter Popov wrote: 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. How does it suggest a storage space with size 0 ? Micha

Re: [fpc-devel] an observation about GetMem

2008-09-04 Thread Peter Popov
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 p being undefined and it is put as a requirement for any custom implementation of a heap manager. Either way would work. Peter On Thu, 04 Sep