| Home | Libraries | People | FAQ | More

## Struct template stored_size

boost::container::stored_size

## Synopsis

    // In header: <boost/container/options.hpp>

    template<typename StoredSizeType>
    struct stored_size {
    };

## Description

This option specifies the unsigned integer type that a user wants the container to use to hold size-related information inside a container (e.g. current size, current capacity).

If the maximum capacity() to be used is limited, a user can try to use 8-bit, 16-bit (e.g. in 32-bit machines), or 32-bit size types (e.g. in a 64 bit machine) to see if some memory can be saved for empty vectors. This could potentially performance benefits due to better cache usage.

Note that alignment requirements can disallow theoretical space savings. Example: `vector` holds a pointer and two size types (for size and capacity), in a 32 bit machine a 8 bit size type (total size: 4 byte pointer + 2 x 1 byte sizes = 6 bytes) will not save space when comparing two 16-bit size types because usually a 32 bit alignment is required for vector and the size will be rounded to 8 bytes. In a 64-bit machine a 16 bit size type does not usually save memory when comparing to a 32-bit size type. Measure the size of the resulting container and do not assume a smaller `stored_size` will always lead to a smaller sizeof(container).

If a user tries to insert more elements than representable by `stored_size`, vector will throw a length_error.

If this option is not specified, `allocator_traits<A>::size_type` (usually std::size_t) will be used to store size-related information inside the container.

### Template Parameters

1.     typename StoredSizeType

   An unsigned integer type. It shall be smaller than than the size of the size_type deduced from ``allocator_traits`<A>::size_type` or the same type.