Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Click here to view the latest version of this page.
PrevUpHomeNext

Class template segment_manager_base

boost::interprocess::segment_manager_base

Synopsis

// In header: <boost/interprocess/segment_manager.hpp>

template<typename MemoryAlgorithm> 
class segment_manager_base {
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;         
  typedef MemoryAlgorithm::multiallocation_chain  multiallocation_chain;      // @ 

  // construct/copy/destruct
  segment_manager_base(std::size_t, std::size_t);

  // public member functions
  std::size_t get_size() const;
  std::size_t get_free_memory() const;
  void * allocate(std::size_t, std::nothrow_t);
  multiallocation_chain allocate_many(std::size_t, std::size_t);
  multiallocation_chain 
  allocate_many(const std::size_t *, std::size_t, std::size_t = 1);
  multiallocation_chain 
  allocate_many(std::size_t, std::size_t, std::nothrow_t);
  multiallocation_chain 
  allocate_many(const std::size_t *, std::size_t, std::size_t, std::nothrow_t);
  void deallocate_many(multiallocation_chain);
  void * allocate(std::size_t);
  void * allocate_aligned(std::size_t, std::size_t, std::nothrow_t);
  void * allocate_aligned(std::size_t, std::size_t);
  template<typename T> 
    std::pair< T *, bool > 
    allocation_command(boost::interprocess::allocation_type, std::size_t, 
                       std::size_t, std::size_t &, T * = 0);
  std::pair< void *, bool > 
  raw_allocation_command(boost::interprocess::allocation_type, std::size_t, 
                         std::size_t, std::size_t &, void * = 0, 
                         std::size_t = 1);
  void deallocate(void *);
  void grow(std::size_t);
  void shrink_to_fit();
  bool all_memory_deallocated();
  bool check_sanity();
  void zero_free_memory();
  std::size_t size(const void *) const;
  void * prot_anonymous_construct(std::size_t, bool, unspecified);
  void prot_anonymous_destroy(const void *, unspecified);

  // public static functions
  static std::size_t get_min_size(std::size_t);
  static const std::size_t PayloadPerAllocation;
};

Description

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/destruct

  1. segment_manager_base(std::size_t size, std::size_t 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 functions

  1. std::size_t get_size() const;

    Returns the size of the memory segment

  2. std::size_t get_free_memory() const;

    Returns the number of free bytes of the memory segment

  3. void * allocate(std::size_t nbytes, std::nothrow_t);

    Allocates nbytes bytes. This function is only used in single-segment management. Never throws

  4. multiallocation_chain 
    allocate_many(std::size_t elem_bytes, std::size_t num_elements);
    @

    Allocates n_elements of elem_size bytes. Throws bad_alloc on failure.

  5. multiallocation_chain 
    allocate_many(const std::size_t * element_lenghts, std::size_t n_elements, 
                  std::size_t sizeof_element = 1);

    Allocates n_elements, each one of element_lenghts[i]*sizeof_element bytes. Throws bad_alloc on failure.

  6. multiallocation_chain 
    allocate_many(std::size_t elem_bytes, std::size_t num_elements, 
                  std::nothrow_t);

    Allocates n_elements of elem_size bytes. Returns a default constructed iterator on failure.

  7. multiallocation_chain 
    allocate_many(const std::size_t * elem_sizes, std::size_t n_elements, 
                  std::size_t sizeof_element, std::nothrow_t);

    Allocates n_elements, each one of element_lenghts[i]*sizeof_element bytes. Returns a default constructed iterator on failure.

  8. void deallocate_many(multiallocation_chain chain);

    Deallocates elements pointed by the multiallocation iterator range.

  9. void * allocate(std::size_t nbytes);

    Allocates nbytes bytes. Throws boost::interprocess::bad_alloc on failure

  10. void * allocate_aligned(std::size_t nbytes, std::size_t alignment, 
                            std::nothrow_t);

    Allocates nbytes bytes. This function is only used in single-segment management. Never throws

  11. void * allocate_aligned(std::size_t nbytes, std::size_t alignment);

    Allocates nbytes bytes. This function is only used in single-segment management. Throws bad_alloc when fails

  12. template<typename T> 
      std::pair< T *, bool > 
      allocation_command(boost::interprocess::allocation_type command, 
                         std::size_t limit_size, std::size_t preferred_size, 
                         std::size_t & received_size, T * reuse_ptr = 0);
  13. std::pair< void *, bool > 
    raw_allocation_command(boost::interprocess::allocation_type command, 
                           std::size_t limit_objects, 
                           std::size_t preferred_objects, 
                           std::size_t & received_objects, void * reuse_ptr = 0, 
                           std::size_t sizeof_object = 1);
  14. void deallocate(void * addr);

    Deallocates the bytes allocated with allocate/allocate_many() pointed by addr

  15. void grow(std::size_t extra_size);

    Increases managed memory in extra_size bytes more. This only works with single-segment management.

  16. void shrink_to_fit();

    Decreases managed memory to the minimum. This only works with single-segment management.

  17. bool all_memory_deallocated();

    Returns the result of "all_memory_deallocated()" function of the used memory algorithm

  18. bool check_sanity();

    Returns the result of "check_sanity()" function of the used memory algorithm

  19. void zero_free_memory();

    Writes to zero free memory (memory not yet allocated) of the memory algorithm

  20. std::size_t size(const void * ptr) const;
    Returns the size of the buffer previously allocated pointed by ptr.
  21. void * prot_anonymous_construct(std::size_t num, bool dothrow, 
                                    unspecified table);
    @ protected:
  22. void prot_anonymous_destroy(const void * object, unspecified table);
    Calls the destructor and makes an anonymous deallocate.

segment_manager_base public static functions

  1. static std::size_t get_min_size(std::size_t size);

    Obtains the minimum size needed by the segment manager


PrevUpHomeNext