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

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Class template rbtree_best_fit



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

template<typename MutexFamily, typename VoidMutex = offset_ptr<void>, 
         std::size_t MemAlignment = 0> 
class rbtree_best_fit {
  // construct/copy/destruct
  rbtree_best_fit(size_type, size_type);

  // public member functions
  void * allocate(size_type);
  void deallocate(void *);
  size_type get_size() const;
  size_type get_free_memory() const;
  void zero_free_memory();
  void grow(size_type);
  void shrink_to_fit();
  bool all_memory_deallocated();
  bool check_sanity();
  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);
  size_type size(const void *) const;
  void * allocate_aligned(size_type, size_type);

  // public static functions
  static size_type get_min_size(size_type);


This class implements an algorithm that stores the free nodes in a red-black tree to have logarithmic search/insert times.

rbtree_best_fit public construct/copy/destruct

  1. rbtree_best_fit(size_type size, size_type extra_hdr_bytes);

    Constructor. "size" is the total size of the managed memory segment, "extra_hdr_bytes" indicates the extra bytes beginning in the sizeof(rbtree_best_fit) offset that the allocator should not use at all.

  2. ~rbtree_best_fit();

rbtree_best_fit public member functions

  1. void * allocate(size_type nbytes);
    Allocates bytes, returns 0 if there is not more memory.
  2. void deallocate(void * addr);
    Deallocates previously allocated bytes.
  3. size_type get_size() const;
    Returns the size of the memory segment.
  4. size_type get_free_memory() const;
    Returns the number of free bytes of the segment.
  5. void zero_free_memory();

    Initializes to zero all the memory that's not in use. This function is normally used for security reasons.

  6. void grow(size_type extra_size);

    Increases managed memory in extra_size bytes more

  7. void shrink_to_fit();
    Decreases managed memory as much as possible.
  8. bool all_memory_deallocated();
    Returns true if all allocated memory has been deallocated.
  9. bool check_sanity();

    Makes an internal sanity check and returns true if success

  10. 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);
  11. std::pair< void *, bool > 
    raw_allocation_command(boost::interprocess::allocation_type command, 
                           size_type limit_object, size_type preferred_object, 
                           size_type & received_object, void * reuse_ptr = 0, 
                           size_type sizeof_object = 1);
  12. size_type size(const void * ptr) const;
    Returns the size of the buffer previously allocated pointed by ptr.
  13. void * allocate_aligned(size_type nbytes, size_type alignment);

    Allocates aligned bytes, returns 0 if there is not more memory. Alignment must be power of 2

rbtree_best_fit public static functions

  1. static size_type get_min_size(size_type extra_hdr_bytes);
    Obtains the minimum size needed by the algorithm.