From: Christopher Kohlhoff (chris_at_[hidden])
Date: 2005-08-31 02:56:39
--- Felipe Magno de Almeida <felipe.m.almeida_at_[hidden]> wrote:
> win_iocp_operation is a base class that takes a pointer to a function
> and when called(when the IO operation is completed) it executes its
> pointer. The pointer is normally a static function to a derived class
> that calls the apropriate handler.
> There's a comment above win_iocp_operation that is this:
> // Base class for all IOCP operations. A function pointer is used
> instead of
> // virtual functions to avoid the associated overhead.
> But I dont quite follow the virtual function overhead in this case. I
> think that asio is reinventing the wheel and with the same overhead.
The overhead is not the virtual function call itself, but all the other
stuff that gets generated by the compiler as soon as you add a virtual
function to a class (e.g. vtable, RTTI etc).
Since you can very easily end up with many win_iocp_operation-derived
classes in your application (one for each callback handler) using
virtual functions can contribute to significant code bloat on some
compilers (e.g. MSVC6, although with MSVC7.1 it appears to optimise
unused RTTI away).
By doing this little workaround, I can guarantee for all compilers that
the overhead for each handler is limited to a single function, which is
called through a function pointer.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk