You might notice that most of the library's functions pass integer objects by value, which strikes most developers as incredibly inefficient. I thought so too, until I read Dave Abrahams' excellent article, "Want Speed? Pass By Value.", which you can find at <http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/>.
To increase the speed of the library further, it uses a copy-on-write system internally. That means that if the internal functions copy an integer object, the copy and the original share the same storage. They are only assigned separate storage when one of them is changed. This mechanism makes copying a number (explicitly, by returning it, or by using it as a non-reference parameter to a function) very fast, regardless of its size.
Unfortunately, copy-on-write isn't compatible with thread-safe operation, so by default the library will ensure that all of its objects have unique storage before they are returned to your program. If you want maximum speed, and can ensure that integer objects are only used in the threads they are created in, you can disable this by using the options::copy_on_write
option on the integer_t
class template.
© Copyright Chad Nelson, 2010-2011. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)