Memory allocation in D
Sean Kelly
sean at f4.ca
Fri Nov 30 18:19:38 PST 2007
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. I also realized that I don't need to
worry about malloc and vmalloc because they're already ANSI C complaint,
so it's just potentially a matter of sorting out VirtualAlloc and mmap.
I'm going to do a bit more research and see what comes out of it.
Sean
More information about the Digitalmars-d
mailing list