Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

boost.variant and its efficiency

49 views
Skip to first unread message

Miroslaw Makowiecki

unread,
Sep 28, 2007, 7:25:49 PM9/28/07
to
What do your think about the efficiency of boost.variant on account of a
memory and a speed of its action in this boost library.
Advice in thanks.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Mathias Gaunard

unread,
Sep 30, 2007, 5:05:23 PM9/30/07
to
On Sep 29, 1:25 am, Miroslaw Makowiecki <tyta...@poczta.onet.pl>
wrote:

> What do your think about the efficiency of boost.variant on account of a
> memory and a speed of its action in this boost library.
> Advice in thanks.

First, boost.variant is move aware, and will try to apply move
semantics when possible. (if your compiler supports rvalue references
or if you use boost.move)
If your class has a nothrow move or nothrow copy, and if you
"document" it as such, boost.variant will only use one unique stack
storage which size and alignment are the maximum possible given the
possible types.
If your move or copy constructors cannot be detected as being nothrow,
it will use an additional temporary heap storage (due to exception-
safety problems in operator=).

As for dispatch, it uses a switch statement, which is highly optimal
too, even more efficient than virtual function calls.

0 new messages