Boost logo

Boost :

Subject: Re: [boost] [smart_ptr] scoped_array / shared_array (size_t) constructor
From: Olaf van der Spek (ml_at_[hidden])
Date: 2011-10-31 16:20:18


On Tue, Oct 25, 2011 at 12:36 AM, Olaf van der Spek <ml_at_[hidden]> wrote:
> Hi,
>
> Currently, one has to manually allocate the array and pass the ptr to
> the constructor of scoped_array / shared_array.
>
> boost::scoped_array<unsigned char> A(new unsigned char[100]);
> boost::shared_array<unsigned char> B(new unsigned char[100]);
>
> This requires one to repeat the type and shared_array requires two
> allocations (one extra for the control block).
> std::vector has a constructor from size_t and one can write:
>
> std::vector<unsigned char> V(100);
>
> This avoids the type duplication and it'd allow shared_array to do
> only a single allocation.
> A few choices have to be made:
> 1. Should "new T[sz]" or "new T[sz]()" be used?
> 2. What should happen when size = 0? Should it call new T[0] or should
> it just use NULL?
>
> https://svn.boost.org/trac/boost/ticket/4637

Is (almost) nobody using scoped/shared_array?

-- 
Olaf

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