Boost logo

Boost :

From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2004-09-22 06:22:29


Maxim Yegorushkin <e-maxim_at_[hidden]> wrote:
> Ben Hutchings <ben.hutchings_at_[hidden]> wrote:
>
> []
>
> > There's one possible problem I noticed, which is that an allocated
> > buffer will be aligned properly for boost::detail::atomic_count but
> > perhaps might not be aligned properly for char_t (or to whatever
> > buffer_storage_alignment specifies). Let me apply the James Kanze
> > test [*]: is it safe to create a const_string<double> on a SPARC?
> >
> > [*] See <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8670> if you
> > don't know what I'm talking about.
>
> I fixed it using the union trick.
>
> But I think there might be another solution. The standard states in
> 5.3.4.10 that arrays of char's allocated with new expression are
> always properly aligned for types whose size is no greater than the
> size of the array. Does allocator<char>::allocate() have the same
> requirement? I could not find it in my copy of the standard.

The default allocator's allocate() member function uses
::operator new(std::size_t) so any specialisation could be used to
allocate memory aligned for any type. However, the requirements for
allocators in general (table 32 in subclause 20.1.5) say only that
"[m]emory is allocated for n objects of type T" by the allocate()
function.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk