Boost logo

Boost :

From: Corwin Joy (cjoy_at_[hidden])
Date: 2001-07-18 19:54:11


I think that a reference counted 'any' object would make a nice addition to
the boost libraries.

Corwin

----- Original Message -----
From: "Fernando Cacciola" <fcacciola_at_[hidden]>
To: "boost" <boost_at_[hidden]>
Sent: Wednesday, July 18, 2001 2:46 PM
Subject: [boost] Reference counting 'any'

> 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
>
>
> Info: http://www.boost.org Unsubscribe:
<mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


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