|
Boost : |
Subject: Re: [boost] [function]functionwrappingwithnoexceptionsafetyguarantee
From: Daniel Walker (daniel.j.walker_at_[hidden])
Date: 2010-11-13 14:40:46
On Mon, Nov 8, 2010 at 7:24 PM, Domagoj Saric <dsaritz_at_[hidden]> wrote:
>
> "Daniel Walker" <daniel.j.walker_at_[hidden]> wrote in message
> news:AANLkTinCj3avcSZtfm9jcCBfmcDVDbSyf4Cu8ZktumwY_at_mail.gmail.com...
>>>
>>> On Sat, Nov 6, 2010 at 7:53 PM, Peter Dimov <pdimov_at_[hidden]> wrote:
>>>>
>>>> This is a special case: all targets are function pointers of the same
>>>> type, right?
>>>
>>> No. It's enough for one of them to be.
>>
>> Oh, I see, if the user ever assigns a function pointer target, then
>> you can reuse the vtable from the empty target. OK, that's a
>> reasonable optimization, but it doesn't decrease the upper bound on
>> space overhead, which is reached when no user-assigned target has the
>> same type as the empty target.
>
> That is not an optimization, it is just the correct way to do it and the way
> the current boost::function implementation already functions...
There is more than one "correct" way to implement the empty static
scheme. The current boost::function implementation does not implement
an empty target. The implementation of the empty static scheme in my
previous patch could be optimized using Peter's suggestion.
I looked into this optimization further and found that it doesn't work
for all function pointer targets, since not all function pointer
targets have the same type as the empty target. Consider the
following:
int f(int) { return 0; }
int main()
{
boost::function<float(float)> g;
g = &f;
}
This is a perfectly valid function pointer assignment, but the empty
target function pointer from the first line of main would have a
different type than the user assigned function pointer on the second
line. So, in this case, the static empty vtable cannot be reused to
store &f.
However, in the case where the user does assign a function pointer
with the same type as the empty target, it seems like a good idea to
reuse the empty vtable per Peter's suggestion. I uploaded a new patch
that implements this optimization as well as the const static vtable
from ticket 4717, so that all space overhead is in the text segment.
https://svn.boost.org/trac/boost/ticket/4803
Peter, if you have time, would you mind taking a look at my patch? Let
me know what you think and if you see any other areas for improvement.
Thanks!
Daniel Walker
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk