|
Boost : |
From: Beman Dawes (bdawes_at_[hidden])
Date: 2005-01-20 13:57:21
At 12:38 PM 1/20/2005, Dave Handley wrote:
><snip on alignment>
>
>Jonathan Wakely wrote:
>
>> > memory is alignment with the type being allocated. Malloc and New
are
>> > guaranteed to return memory that is aligned for an object of that
size
>>
>> Guaranteed to be aligned for _any_ type, isn't it ?
>
>Any type that is not bigger than the memory size allocated. I'm
>pretty sure that the ANSI requirement for malloc and new does not
>require alignment to 8/16 byte blocks for memory allocations of a
>single byte (for example). This means that, to be pedantic, a 1 byte
>allocation is not guaranteed to be aligned for a double (for example).
For for malloc, the C++ standard just refers to the C standard, so the C
standard is what applies. Here is what it says:
"The pointer returned if the allocation succeeds is suitably aligned so
that it may be assigned to a pointer to any type of object and then used to
access such an object or an array of such objects in the space allocated
(until the space is explicitly deallocated)."
There is no discussion of the size of the allocation having any impact on
the alignment of the returned pointer.
--Beman
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk