Boost logo

Boost :

Subject: Re: [boost] [system][filesystem v3] Question about error_code arguments
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2009-10-20 22:40:50


Stewart, Robert wrote:
> Andrey Semashev wrote:
>> Stewart, Robert wrote:
>>> Beman Dawes wrote:
>>>
>>> set, then there's no need for a null reference. Unfortunately,
>>> that has a performance downside: the function must be called and
>>> the temporary must be created or a reference to a global object
>>> must be created for all calls that use the default. A null
>>> pointer default must be cheaper.
>> I think the performance cost of checking a reference or pointer for
>> validity and checking some property in the error_code instance
>> will be the same. After all, in both cases it comes down to a
>> single comparison of two integers. Even if referencing the global
>> default instance does add overhead, I bet it is negligible.
>
> I wasn't referring to checking the reference or pointer. Rather, I
> was pointing out that the reference must be bound to something when
> the default is accepted. Every call using the default implies code
> that acquires an object or reference to one to which the formal
> parameter can be bound. That is costlier than simply passing a null
> pointer unless some compiler magic is involved.

The call to throws() can be inlined so that the global object
acquisition turns into loading its address in a register. The address is
known at compile time, so there's little difference between loading a
zero into a pointer/reference argument and loading a valid address into
a reference argument. No magic needed for this to happen.


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