Boost logo

Boost :

Subject: Re: [boost] [align] Review - Impl Evaluation Part 1.
From: Mostafa (mostafa_working_away_at_[hidden])
Date: 2014-04-15 19:19:45


Glen Fernandes <glen.fernandes <at> gmail.com> writes:

>
> On Sat, Apr 12, 2014 at 1:11 PM, Mostafa <mostafa_working_away <at>
yahoo.com> wrote:
> > Unfortunately I don't understand what you're trying to say.
Additionally let
> > me rephrase my question, why is it that in the absence of a
> > platform-specific aligned_alloc the boost provided aligned_alloc
silently
> > aligns on alignof(void *) if the user requested alignment value is less
than
> > alignof(void *)? (I understand this is still correct behaviour, just
curious
> > since the boost provided aligned_alloc uses boost::align to align the
memory
> > buffer and, per your previous response, "An alignment smaller than
> > alignof(void*) is still a valid fundamental alignment, so align()
should be
> > usable with such values.")
>
> Ah, I had misinterpreted your question. The reason why the
> Boost-provided aligned_alloc will ensure alignment is a minimum of
> alignof(void*), is because after calling align(), we want to access
> the sizeof(void*) bytes immediately preceding the aligned memory as a
> void*, so that address must be suitably aligned for void*.
>
> Instead of *(static_cast<void*>(p1) - 1) = p2; I could have used
> std::memcpy to copy p2 into that storage, and then it would not
> require that storage to be at-least alignof(void*) aligned.
 
Thanks for the explanation. Then I think the documentation
for aligned_alloc needs to be updated from:
  "... by an additional sizeof(void*) and alignment bytes."
to:
  "... by an additional sizeof(void*) and max(alignment, sizeof(void *))
   bytes."
to take into account the silent alignment bumping that may occur in some
scenarios.


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