Boost logo

Boost :

Subject: Re: [boost] [smart_ptr] scoped_array / shared_array (size_t) constructor
From: Ivan Sorokin (vanyacpp_at_[hidden])
Date: 2011-10-26 17:02:02


On 25.10.2011 02:36, Olaf van der Spek wrote:
> 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);
Maybe off-topic, but why should one prefer scoped_array to vector? Just
curious, I never used it myself.
> 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
>


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