Boost logo

Boost :

From: Glen Fernandes (glen.fernandes_at_[hidden])
Date: 2020-01-29 04:56:29


On Tue, Jan 28, 2020 at 10:51 PM Gavin Lambert via Boost
<boost_at_[hidden]> wrote:
>
> On 25/01/2020 01:21, Glen Fernandes wrote:
> > Heap storage, fixed size at runtime:
> > allocate_unique<T[]>(alloc, size, ...)
> >
> > Gives users everything they need for buffers. (They don't need a Container
> > that is copyable).
>
> Not quite. These keep the storage pointer and the storage size
> separately,

Yes quite. i.e. What you believe is not true boost::allocate_unique.

i.e. For auto p = boost::allocate_unique<T[]>(a, n);
     assert(p.get().size() == n);

This is because the unique_ptr stores a pointer adaptor around the
Allocator::pointer which also stores the size.

So the pointer and size are stored together in the unique_ptr result.

To get the plain Allocator::pointer out of it you can use p.get().ptr()

Or, for example, p.release().ptr() for someone who wants to manage
it themselves.

Glen


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