| Home | Libraries | People | FAQ | More

## Class template segment_manager

boost::interprocess::segment_manager

## Synopsis

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

    template<typename CharType, typename MemoryAlgorithm,
             template< class IndexConfig > class IndexType>
    class segment_manager :
      public boost::interprocess::segment_manager_base< MemoryAlgorithm >
    {
    public:
      // types
      typedef MemoryAlgorithm                                                                 memory_algorithm;
      typedef Base::void_pointer                                                              void_pointer;
      typedef CharType                                                                        char_type;
      typedef segment_manager_base< MemoryAlgorithm >                                         segment_manager_base_type;
      typedef unspecified                                                                     index_config_named;         // @ private:
      typedef unspecified                                                                     index_config_unique;
      typedef IndexType< index_config_named >                                                 index_type;
      typedef unspecified                                                                     is_intrusive_t;
      typedef unspecified                                                                     is_node_index_t;
      typedef IndexType< index_config_named >                                                 named_index_t;
      typedef IndexType< index_config_unique >                                                unique_index_t;
      typedef unspecified                                                                     char_ptr_holder_t;
      typedef unspecified                                                                     named_transform;
      typedef unspecified                                                                     unique_transform;
      typedef Base::mutex_family                                                              mutex_family;
      typedef transform_iterator< typename named_index_t::const_iterator, named_transform >   const_named_iterator;
      typedef transform_iterator< typename unique_index_t::const_iterator, unique_transform > const_unique_iterator;

      // member classes/structs/unions
      template<typename T>
      struct allocator {
        // types
        typedef boost::interprocess::allocator< T, segment_manager > type;
      };

      // Constructor proxy object definition helper class.
      template<typename T>
      struct construct_iter_proxy {
        // types
        typedef unspecified type;
      };
      template<typename T>
      struct construct_proxy {
        // types
        typedef unspecified type;
      };
      template<typename T>
      struct deleter {
        // types
        typedef boost::interprocess::deleter< T, segment_manager > type;
      };

      struct header_t {
        // construct/copy/destruct
        header_t(Base *);
        named_index_t m_named_index;
        unique_index_t m_unique_index;
      };

      // construct/copy/destruct
      segment_manager();
      segment_manager(const segment_manager &);
      segment_manager(std::size_t);
      segment_manager& operator=(const segment_manager &);

      // private member functions
      template<typename T>
        std::pair< T *, std::size_t > priv_find_impl(const CharType *, bool);
      template<typename T>
        std::pair< T *, std::size_t > priv_find__impl(unspecified, bool);
      void * priv_generic_construct(const CharType *, std::size_t, bool, bool,
                                    unspecified);
      void priv_destroy_ptr(const void *, unspecified);
      template<typename CharT>
        void * priv_generic_find(const CharT *, unspecified, unspecified,
                                 std::size_t &, unspecified, bool);
      template<typename CharT>
        void * priv_generic_find(const CharT *, unspecified, unspecified,
                                 std::size_t &, unspecified, bool);
      template<typename CharT>
        bool priv_generic_named_destroy(block_header_t *, unspecified,
                                        unspecified, unspecified);
      template<typename CharT>
        bool priv_generic_named_destroy(block_header_t *, unspecified,
                                        unspecified, unspecified);
      template<typename CharT>
        bool priv_generic_named_destroy(const CharT *, unspecified, unspecified,
                                        unspecified);
      template<typename CharT>
        bool priv_generic_named_destroy(const CharT *, unspecified, unspecified,
                                        unspecified);
      template<typename CharT>
        bool priv_generic_named_destroy_impl(unspecified, unspecified,
                                             unspecified);
      template<typename CharT>
        void * priv_generic_named_construct(std::size_t, const CharT *,
                                            std::size_t, bool, bool, unspecified,
                                            unspecified, unspecified);
      template<typename CharT>
        void * priv_generic_named_construct(std::size_t, const CharT *,
                                            std::size_t, bool, bool, unspecified,
                                            unspecified, unspecified);
      segment_manager * get_this_pointer();
      scoped_lock< rmutex > priv_get_lock(bool);

      // public member functions
      template<typename T> std::pair< T *, std::size_t > find(const CharType *);
      template<typename T> std::pair< T *, std::size_t > find(unspecified);
      template<typename T>
        std::pair< T *, std::size_t > find_no_lock(const CharType *);
      template<typename T> std::pair< T *, std::size_t > find_no_lock(unspecified);
      template<typename T> construct_proxy< T >::type construct(char_ptr_holder_t);
      template<typename T>
        construct_proxy< T >::type find_or_construct(char_ptr_holder_t);
      template<typename T>
        construct_proxy< T >::type construct(char_ptr_holder_t, std::nothrow_t);
      template<typename T>
        construct_proxy< T >::type
        find_or_construct(char_ptr_holder_t, std::nothrow_t);
      template<typename T>
        construct_iter_proxy< T >::type construct_it(char_ptr_holder_t);
      template<typename T>
        construct_iter_proxy< T >::type find_or_construct_it(char_ptr_holder_t);
      template<typename T>
        construct_iter_proxy< T >::type
        construct_it(char_ptr_holder_t, std::nothrow_t);
      template<typename T>
        construct_iter_proxy< T >::type
        find_or_construct_it(char_ptr_holder_t, std::nothrow_t);
      template<typename Func> *void atomic_func(Func &);
      template<typename Func> bool try_atomic_func(Func &);
      template<typename T> bool destroy(unspecified);
      template<typename T> bool destroy(const CharType *);
      template<typename T> void destroy_ptr(const T *);
      void reserve_named_objects(std::size_t);
      void reserve_unique_objects(std::size_t);
      void shrink_to_fit_indexes();
      std::size_t get_num_named_objects();
      std::size_t get_num_unique_objects();
      const_named_iterator named_begin() const;
      const_named_iterator named_end() const;
      const_unique_iterator unique_begin() const;
      const_unique_iterator unique_end() const;
      template<typename T> allocator< T >::type get_allocator();
      template<typename T> deleter< T >::type get_deleter();
      template<typename T>
        T * generic_construct(const CharType *, std::size_t, bool, bool,
                              unspecified);

      // public static functions
      template<typename T> static const CharType * get_instance_name(const T *);
      template<typename T> static std::size_t get_instance_length(const T *);
      template<typename T> static instance_type get_instance_type(const T *);
      static std::size_t get_min_size();

      // private static functions
      static const CharType * priv_get_instance_name(block_header_t *);
      static std::size_t priv_get_instance_length(block_header_t *, std::size_t);
      static instance_type priv_get_instance_type(block_header_t *);
      static std::size_t priv_get_reserved_bytes();
      static const std::size_t PayloadPerAllocation;
    };

## Description

This object is placed in the beginning of memory segment and implements the allocation (named or anonymous) of portions of the segment. This object contains two indexes that maintain an association between a name and a portion of the segment.

The first index contains the mappings for normal named objects using the char type specified in the template parameter.

The second index contains the association for unique instances. The key will be the const char * returned from type_info.name() function for the unique type to be constructed.

segment_manager<CharType, MemoryAlgorithm, IndexType> inherits publicly from segment_manager_base<MemoryAlgorithm> and inherits from it many public functions related to anonymous object and raw memory allocation. See segment_manager_base reference to know about those functions.

### `segment_manager` public construct/copy/destruct

1.     segment_manager();

   @ //Non-copyable

2.     segment_manager(const segment_manager &);

3.     segment_manager(std::size_t size);

   Constructor of the segment manager "size" is the size of the memory segment where the segment manager is being constructed. Can throw

4.     segment_manager& operator=(const segment_manager &);

### `segment_manager` private member functions

1.     template<typename T>
         std::pair< T *, std::size_t >
         priv_find_impl(const CharType * name, bool lock);

   Tries to find a previous named allocation. Returns the address and the object count. On failure the first member of the returned pair is 0.

2.     template<typename T>
         std::pair< T *, std::size_t > priv_find__impl(unspecified name, bool lock);

   Tries to find a previous unique allocation. Returns the address and the object count. On failure the first member of the returned pair is 0.

3.     void * priv_generic_construct(const CharType * name, std::size_t num,
                                     bool try2find, bool dothrow, unspecified table);

4.     void priv_destroy_ptr(const void * ptr, unspecified dtor);

5.     template<typename CharT>
         void * priv_generic_find(const CharT * name, unspecified index,
                                  unspecified table, std::size_t & length,
                                  unspecified is_intrusive, bool use_lock);

6.     template<typename CharT>
         void * priv_generic_find(const CharT * name, unspecified index,
                                  unspecified table, std::size_t & length,
                                  unspecified is_intrusive, bool use_lock);

7.     template<typename CharT>
         bool priv_generic_named_destroy(block_header_t * block_header,
                                         unspecified index, unspecified table,
                                         unspecified is_node_index);

8.     template<typename CharT>
         bool priv_generic_named_destroy(block_header_t * block_header,
                                         unspecified index, unspecified table,
                                         unspecified is_node_index);

9.     template<typename CharT>
         bool priv_generic_named_destroy(const CharT * name, unspecified index,
                                         unspecified table,
                                         unspecified is_intrusive_index);

10.     template<typename CharT>
          bool priv_generic_named_destroy(const CharT * name, unspecified index,
                                          unspecified table,
                                          unspecified is_intrusive_index);

11.     template<typename CharT>
          bool priv_generic_named_destroy_impl(unspecified it, unspecified index,
                                               unspecified table);

12.     template<typename CharT>
          void * priv_generic_named_construct(std::size_t type, const CharT * name,
                                              std::size_t num, bool try2find,
                                              bool dothrow, unspecified table,
                                              unspecified index,
                                              unspecified is_intrusive);

13.     template<typename CharT>
          void * priv_generic_named_construct(std::size_t type, const CharT * name,
                                              std::size_t num, bool try2find,
                                              bool dothrow, unspecified table,
                                              unspecified index,
                                              unspecified is_intrusive);

    Generic named new function for named functions

14.     segment_manager * get_this_pointer();

    Returns the this pointer.

15.     scoped_lock< rmutex > priv_get_lock(bool use_lock);

### `segment_manager` public member functions

1.     template<typename T> std::pair< T *, std::size_t > find(const CharType * name);

   Tries to find a previous named allocation. Returns the address and the object count. On failure the first member of the returned pair is 0.

2.     template<typename T> std::pair< T *, std::size_t > find(unspecified name);

   Tries to find a previous unique allocation. Returns the address and the object count. On failure the first member of the returned pair is 0.

3.     template<typename T>
         std::pair< T *, std::size_t > find_no_lock(const CharType * name);

   Tries to find a previous named allocation. Returns the address and the object count. On failure the first member of the returned pair is 0. This search is not mutex-protected!

4.     template<typename T>
         std::pair< T *, std::size_t > find_no_lock(unspecified name);

   Tries to find a previous unique allocation. Returns the address and the object count. On failure the first member of the returned pair is 0. This search is not mutex-protected!

5.     template<typename T>
         construct_proxy< T >::type construct(char_ptr_holder_t name);

   Returns throwing "construct" proxy object

6.     template<typename T>
         construct_proxy< T >::type find_or_construct(char_ptr_holder_t name);

   Returns throwing "search or construct" proxy object

7.     template<typename T>
         construct_proxy< T >::type construct(char_ptr_holder_t name, std::nothrow_t);

   Returns no throwing "construct" proxy object

8.     template<typename T>
         construct_proxy< T >::type
         find_or_construct(char_ptr_holder_t name, std::nothrow_t);

   Returns no throwing "search or construct" proxy object

9.     template<typename T>
         construct_iter_proxy< T >::type construct_it(char_ptr_holder_t name);

   Returns throwing "construct from iterators" proxy object.

10.     template<typename T>
          construct_iter_proxy< T >::type find_or_construct_it(char_ptr_holder_t name);

    Returns throwing "search or construct from iterators" proxy object

11.     template<typename T>
          construct_iter_proxy< T >::type
          construct_it(char_ptr_holder_t name, std::nothrow_t);

    Returns no throwing "construct from iterators" proxy object

12.     template<typename T>
          construct_iter_proxy< T >::type
          find_or_construct_it(char_ptr_holder_t name, std::nothrow_t);

    Returns no throwing "search or construct from iterators" proxy object

13.     template<typename Func> *void atomic_func(Func & f);

    Calls object function blocking recursive interprocess_mutex and guarantees that no new named_alloc or destroy will be executed by any process while executing the object function call

14.     template<typename Func> bool try_atomic_func(Func & f);

    Tries to calls a functor guaranteeing that no new construction, search or destruction will be executed by any process while executing the object function call. If the atomic function can't be immediatelly executed because the internal mutex is already locked, returns false. If the functor throws, this function throws.

15.     template<typename T> bool destroy(unspecified);

    Destroys a previously created unique instance. Returns false if the object was not present.

16.     template<typename T> bool destroy(const CharType * name);

    Destroys the named object with the given name. Returns false if that object can't be found.

17.     template<typename T> void destroy_ptr(const T * p);

    Destroys an anonymous, unique or named object using it's address

18.     void reserve_named_objects(std::size_t num);

    Preallocates needed index resources to optimize the creation of "num" named objects in the managed memory segment. Can throw boost::interprocess::bad_alloc if there is no enough memory.

19.     void reserve_unique_objects(std::size_t num);

    Preallocates needed index resources to optimize the creation of "num" unique objects in the managed memory segment. Can throw boost::interprocess::bad_alloc if there is no enough memory.

20.     void shrink_to_fit_indexes();

    Calls shrink_to_fit in both named and unique object indexes to try to free unused memory from those indexes.

21.     std::size_t get_num_named_objects();

    Returns the number of named objects stored in the segment.

22.     std::size_t get_num_unique_objects();

    Returns the number of unique objects stored in the segment.

23.     const_named_iterator named_begin() const;

    Returns a constant iterator to the beginning of the information about the named allocations performed in this segment manager

24.     const_named_iterator named_end() const;

    Returns a constant iterator to the end of the information about the named allocations performed in this segment manager

25.     const_unique_iterator unique_begin() const;

    Returns a constant iterator to the beginning of the information about the unique allocations performed in this segment manager

26.     const_unique_iterator unique_end() const;

    Returns a constant iterator to the end of the information about the unique allocations performed in this segment manager

27.     template<typename T> allocator< T >::type get_allocator();

    Returns an instance of the default allocator for type T initialized that allocates memory from this segment manager.

28.     template<typename T> deleter< T >::type get_deleter();

    Returns an instance of the default allocator for type T initialized that allocates memory from this segment manager.

29.     template<typename T>
          T * generic_construct(const CharType * name, std::size_t num, bool try2find,
                                bool dothrow, unspecified table);

    @ Generic named/anonymous new function. Offers all the possibilities, such as throwing, search before creating, and the constructor is encapsulated in an object function.

### `segment_manager` public static functions

1.     template<typename T> static const CharType * get_instance_name(const T * ptr);

   Returns the name of an object created with construct/find_or_construct functions. Does not throw

2.     template<typename T> static std::size_t get_instance_length(const T * ptr);

   Returns the length of an object created with construct/find_or_construct functions. Does not throw.

3.     template<typename T> static instance_type get_instance_type(const T * ptr);

   Returns is the the name of an object created with construct/find_or_construct functions. Does not throw

4.     static std::size_t get_min_size();

   Obtains the minimum size needed by the segment manager

### `segment_manager` private static functions

1.     static const CharType * priv_get_instance_name(block_header_t * ctrl_data);

   Returns the name of an object created with construct/find_or_construct functions. Does not throw

2.     static std::size_t
       priv_get_instance_length(block_header_t * ctrl_data, std::size_t sizeofvalue);

3.     static instance_type priv_get_instance_type(block_header_t * ctrl_data);

   Returns is the the name of an object created with construct/find_or_construct functions. Does not throw

4.     static std::size_t priv_get_reserved_bytes();