Subject: [boost] [smart_ptr] scoped_array / shared_array (size_t) constructor
From: Olaf van der Spek (ml_at_[hidden])
Date: 2011-10-24 18:36:46
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);
boost::shared_array<unsigned char> B(new unsigned char);
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 or should
it just use NULL?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk