|
Boost : |
Subject: Re: [boost] [system][filesystem v3] Question about error_code arguments
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2009-10-20 22:47:49
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.
>
> PS: This was one of the main reasons why the POSIX/C++ group is
> in favour of the pointer.
If the global object is used so often, it will likely be in cache. If
not often, it doesn't matter. An whether the compiler can load a
structure of size equal to int into a register is a question of the
compiler's prosperity.
Anyway, I'd prefer code clarity in this case instead of a possible tiny
performance gain that will be swallowed by the surrounding code.
Consider it in comparison with a file system operation cost, for example.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk