...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::interprocess::segment_manager_base
// In header: <boost/interprocess/segment_manager.hpp> template<typename MemoryAlgorithm> class segment_manager_base : private MemoryAlgorithm { public: // types typedef segment_manager_base< MemoryAlgorithm > segment_manager_base_type; typedef MemoryAlgorithm::void_pointer void_pointer; typedef MemoryAlgorithm::mutex_family mutex_family; typedef MemoryAlgorithm memory_algorithm; // construct/copy/destruct segment_manager_base(size_type, size_type); // public member functions size_type get_size() const; size_type get_free_memory() const; void * allocate(size_type, std::nothrow_t); void * allocate(size_type); void * allocate_aligned(size_type, size_type, std::nothrow_t); void * allocate_aligned(size_type, size_type); template<typename T> std::pair< T *, bool > allocation_command(boost::interprocess::allocation_type, size_type, size_type, size_type &, T * = 0); std::pair< void *, bool > raw_allocation_command(boost::interprocess::allocation_type, size_type, size_type, size_type &, void * = 0, size_type = 1); void deallocate(void *); void grow(size_type); void shrink_to_fit(); bool all_memory_deallocated(); bool check_sanity(); void zero_free_memory(); size_type size(const void *) const; // public static functions static size_type get_min_size(size_type); // public data members static const size_type PayloadPerAllocation; };
This object is the public base class of segment manager. This class only depends on the memory allocation algorithm and implements all the allocation features not related to named or unique objects.
Storing a reference to segment_manager forces the holder class to be dependent on index types and character types. When such dependence is not desirable and only anonymous and raw allocations are needed, segment_manager_base is the correct answer.
segment_manager_base
public
construct/copy/destructsegment_manager_base(size_type sz, size_type reserved_bytes);
Constructor of the segment_manager_base
"size" is the size of the memory segment where the basic segment manager is being constructed.
"reserved_bytes" is the number of bytes after the end of the memory algorithm object itself that the memory algorithm will exclude from dynamic allocation
Can throw
segment_manager_base
public member functionssize_type get_size() const;
Returns the size of the memory segment
size_type get_free_memory() const;
Returns the number of free bytes of the memory segment
void * allocate(size_type nbytes, std::nothrow_t);
Allocates nbytes bytes. This function is only used in single-segment management. Never throws
void * allocate(size_type nbytes);
Allocates nbytes bytes. Throws boost::interprocess::bad_alloc
on failure
void * allocate_aligned(size_type nbytes, size_type alignment, std::nothrow_t);
Allocates nbytes bytes. This function is only used in single-segment management. Never throws
void * allocate_aligned(size_type nbytes, size_type alignment);
Allocates nbytes bytes. This function is only used in single-segment management. Throws bad_alloc
when fails
template<typename T> std::pair< T *, bool > allocation_command(boost::interprocess::allocation_type command, size_type limit_size, size_type preferred_size, size_type & received_size, T * reuse_ptr = 0);
std::pair< void *, bool > raw_allocation_command(boost::interprocess::allocation_type command, size_type limit_objects, size_type preferred_objects, size_type & received_objects, void * reuse_ptr = 0, size_type sizeof_object = 1);
void deallocate(void * addr);
Deallocates the bytes allocated with allocate/allocate_many() pointed by addr
void grow(size_type extra_size);
Increases managed memory in extra_size bytes more. This only works with single-segment management.
void shrink_to_fit();
Decreases managed memory to the minimum. This only works with single-segment management.
bool all_memory_deallocated();
Returns the result of "all_memory_deallocated()" function of the used memory algorithm
bool check_sanity();
Returns the result of "check_sanity()" function of the used memory algorithm
void zero_free_memory();
Writes to zero free memory (memory not yet allocated) of the memory algorithm
size_type size(const void * ptr) const;Returns the size of the buffer previously allocated pointed by ptr.