|
Boost : |
From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-07-18 14:46:43
I'd like to propose a variation of the 'any' class that addresses the
following issue:
Consider:
any foo()
{
std::vector v(UINT_MAX,0);
any r = v ;
return v ;
}
void bar()
{
// The entire vector is copied here.
any r = foo();
}
Currently, 'any' has a copy-on-copy policy; that is, each time an 'any'
instance is copied, the value it holds is copied too.
This policy is appropriate for small objects, but it is very inefficient if
the values held are big.
I've written two variant classes (see
http://www.cuj.com/articles/2000/0010/0010a/0010a.htm?topic=articles), one
of which is pretty much the same as 'any'.
The other class has a share-on-copy policy, just like a read-only
std::string; that is, the value is held in a reference counted dynamically
allocated object.
According to my user reports, both variations are equally useful in their
own domains.
Using boost::shared_ptr it is trivial to implement this 'any' variation.
I attached 'any2.hpp' which is the implementation of this variation.
I named it any2 provisionally, since I can't think of a proper name yet.
Let me know what do you think.
Regards,
Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk