Boost logo

Boost :

From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2008-06-07 16:37:18


On Sat, Jun 7, 2008 at 1:40 PM, Marco Costalba <mcostalba_at_[hidden]> wrote:
> On Sat, Jun 7, 2008 at 3:17 AM, Giovanni Piero Deretta
> <gpderetta_at_[hidden]> wrote:
>>
>> I think that Marco's MSF was an hibryd of both: it (always) performed
>> type erasures and it could store different functions. Unfortunately it
>> lacked direct support for polymorphic function objects and stored
>> every function object in the overload set in a different
>> boost::function, making the size of msf explode.
>
> Well, " making the size of msf explode" it seems to me a little bit on
> the scary side ;-)
>
> Just to clear what we are taking about:
>
> For NON polymorphic function objects or standard functions
>
> sizeof(msf) = sizeof(boost::function) * num_signatures;
>
> For polymorphic function objects
>
> sizeof(msf) = sizeof(boost::function) * num_signatures + sizeof(pointer);
>
>
> Note that this is INDEPENDENT of how many function objects you bind,
> be them standard or polymorphic.

Yep sorry. It depends only on the number of signatures.

It is fine even if not ideal if you use MSF as an overload set: in
this case you still need a pointer for every overload, you waste an
extra pointer for a vtable for every signature, but it is still the
same O(N) space complexity.

It will still be unacceptable for my use case, where I have a single
function object and multiple signatures: it can be implemented with
just a single pointer to the stored object and a single vtable
pointer. I plan to store many of these objects (with *many*
signatures) in containers, so wasting space is not an option.

<good stuff snipped>

>
> Finally both with standard function objects and with polymorphic
> function objects you can ask MSF (for semantic purposes) to create
> only ONE copy of your object, so in ALL the cases the added size,
> implementation dependent, is just what is written above no more no
> less.
>
> So I would dare to say that IMHO MSF does NOT lack (direct) support
> for polymorphic function objects.
>

I forgot you added support the extra pointer to prevent storing a copy
of the same function object to every signature. So yes, it does
support polymorphic function objects without making multiple copies.
But IMHO It seems kludgey that it needs a different boost::function
per signature :(

-- 
gpd

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