Boost logo

Boost :

Subject: Re: [boost] [system][filesystem v3] Question about error_code arguments
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-10-20 18:24:02


AMDG

Detlef Vollmann wrote:
> Andrey Semashev wrote:
>> 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.
> No, it isn't. The null pointer will be in a register, while the
> global object might not even be in the cache.
> And this for functions that are called by the thousands per second
> on a busy server.
>
> Detlef
>
> PS: This was one of the main reasons why the POSIX/C++ group is
> in favour of the pointer.

Why does the global object need to be read?

static error_code throws_;

error_code& throws() { return(throws_); }

void f(error_code& ec = throws()) {
    if(&ec == &throws()) {
        throw ...;
    } else {
        ....
    }
}

This should not actually load anything except the address of
the global error_code. The only advantage of using a null pointer
is that it can be checked with a slightly simpler instruction.

In Christ,
Steven Watanabe


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