Memory allocation in D
James Dennett
jdennett at acm.org
Wed Dec 19 07:58:35 PST 2007
Sean Kelly wrote:
> Sean Kelly wrote:
>> Jason House wrote:
>>>
>>> If object sizes are a power of 2, is that because of special padding
>>> of a
>>> struct/object to make it align well? Maybe some clever trick could
>>> be done
>>> to use wasted space, if it exists, for special tracking data...
>>> Otherwise,
>>> allocating a bit more seems the most sensible.
>>
>> Only arrays get the +1 byte added to their size during allocations.
>> If an object occupies 16 bytes then it will end up in a 16 byte
>> bucket. The +1 issue for arrays exists to make the program a bit more
>> forgiving for "past the end" errors. Interestingly, the ANSI C
>> standard actually requires this behavior in its allocators.
>
> So I went and looked up the clause and I'm not clear whether it requires
> the location to be physically available or merely fore the address to be
> valid for pointer mathematics.
C and C++ only require that the address be valid for pointer
arithmetic; it need not be dereferencable.
-- James
More information about the Digitalmars-d
mailing list