Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-12-16 14:26:00


Thorsten Ottosen:

> Joaquin M Lopez Munoz skrev:
>> Thorsten Ottosen <thorsten.ottosen <at> dezide.com> writes:
>
>>> I would use it as a lightweight and more convenient replacement for
>>> boost::shared_ptr<const T>.
>>>
>>> In my application I might have < 50 objects that needs to by flyweights.
>>> They are almost never identical, and if they are, the memory occupied by
>>> the factory would probably be much larger than that of duplication.
>>
>> Well, then you might not need using the flyweight idiom
>> after all...
>
> Well, it's lower overhead (if no factory and forwarding
> constructors/operations makes it a better choice than shared_ptrconst T>.

It might be possible to do this using a custom factory along the lines of:

template<class T> struct sp_factory
{
    typedef boost::shared_ptr<T const> handle_type;

    handle_type insert( T const & t ) { return handle_type( new T( t ) ); }
    void erase( handle_type ) {}
    T const & entry( handle_type p ) { return *p; }
};

but there's no way to tell from the documentation; it never describes how
the Factory template parameter is actually used.

http://svn.boost.org/svn/boost/sandbox/flyweight/libs/flyweight/doc/reference/flyweight.html#flyweight

As I read it, a flyweight<> can ignore all of its template parameters beyond
T and still conform to its spec, which is probably not what's intended.


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