From: Howard Hinnant (hinnant_at_[hidden])
Date: 2004-01-22 10:43:15
On Jan 22, 2004, at 8:53 AM, Bronek Kozicki wrote:
> Peter Dimov <pdimov_at_[hidden]> wrote:
>> The main (and probably only) selling point of scoped_*, move_* and
>> auto_* is that they have no size overhead, i.e. sizeof(scoped_*<T>)
> The second strong difference is copy semantics. You may pass *ptr
> by value without copying whole allocated memory to new object. In fact,
> we have 3 different copy semantics for arrays:
> * deep copy (std::vector)
> * shallow copy (boost::shared_array)
> * move instead of copy (subject of current discussion)
> There is also difference on how memory is being released:
> * implementation defined (std::vector)
> * full deleter support (boost::shared_array)
> * limited deleter or no deleter at all (subject of current discussion)
More discussion of selling points:
* The ability to transfer ownership of the buffer. This is really
just a generalization of move:
move: transfers ownership of buffer to the same type, implicitly if
from an rvalue.
release: relinquishes ownership to anyone who wants to call release().
The latter is very important in the exception safety patterns:
temporarily grab ownership of a buffer with move_ptr<T>, call other
(possibly throwing) initialization functions for your class, then
transfer ownership from your temporary move_ptr<T> to your class.
* When you want to guarantee unique ownership: For example if your
class Foo wants to own a buffer of T, and not accidently make a copy of
it, move_ptr<T> for a data member is a reasonable choice over
vector<T>. Foo's copy ctor will be automatically disabled instead of
automatically generating a copy of the buffer. Foo's author will have
to take explicit action to do anything else.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk