Updated and documented non-standard optimizations based on memset

This commit is contained in:
Ion Gaztañaga
2014-07-20 14:43:12 +02:00
parent 819b365f5e
commit 941eb27e1d
3 changed files with 32 additions and 7 deletions

View File

@@ -862,6 +862,31 @@ If you need a memory optimized version of `boost::container::vector<bool>`, plea
[endsect]
[section:non_standard_memset_initialization Non-standard value initialization using `std::memset`]
[*Boost.Container] uses `std::memset` with a zero value to initialize some types as in most platforms this
initialization yields to the desired value initialization with improved performance.
Following the C11 standard, [*Boost.Container] assumes that ['for any integer type,
the object representation where all the bits are zero shall be a representation of the value
zero in that type]. Since `_Bool`/`wchar_t`/`char16_t`/`char32_t` are also integer types in C, it considers
all C++ integral types as initializable via `std::memset`.
By default, [*Boost.Container] also considers floating point types to be initializable using `std::memset`.
Most platforms are compatible with this initialization, but in case this initialization is not desirable the
user can `#define BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_NOT_ZERO` before including library headers.
By default, it also considers pointer types (pointer and pointer to function types, excluding
member object and member function pointers) to be initializable using `std::memset`.
Most platforms are compatible with this initialization, but in case this initialization is not desired the
user can `#define BOOST_CONTAINER_MEMZEROED_POINTER_IS_NOT_ZERO` before including library headers.
If neither `BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_NOT_ZERO` nor
`BOOST_CONTAINER_MEMZEROED_POINTER_IS_NOT_ZERO` is defined [*Boost.Container] also considers POD
types to be value initializable via `std::memset` with value zero.
[endsect]
[endsect]
[section:known_issues Known Issues]

View File

@@ -396,14 +396,14 @@ struct is_memzero_initializable
{
typedef typename ::std::iterator_traits<O>::value_type value_type;
static const bool value = are_elements_contiguous<O>::value &&
( ::boost::is_integral<value_type>::value
#if BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL
( ::boost::is_integral<value_type>::value || ::boost::is_enum<value_type>::value
#if defined(BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL)
|| ::boost::is_pointer<value_type>::value
#endif
#if BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO
#if defined(BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO)
|| ::boost::is_floating_point<value_type>::value
#endif
#if BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO && BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL
#if defined(BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO) && defined(BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL)
|| ::boost::is_pod<value_type>::value
#endif
);

View File

@@ -50,12 +50,12 @@
//
//If your platform does not offer these guarantees
//define these to value zero.
#ifndef BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO
#ifndef BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_NOT_ZERO
#define BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO 1
#endif
#ifndef BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL
#define BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL 1
#ifndef BOOST_CONTAINER_MEMZEROED_POINTER_IS_NOT_NULL
#define BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL
#endif
#include <boost/container/detail/config_end.hpp>