Simple Segregated Storage is the simplest, and probably the fastest, memory allocation/deallocation algorithm. More...
#include <simple_segregated_storage.hpp>
Public Types | |
typedef SizeType | size_type |
Public Member Functions | |
simple_segregated_storage () | |
void | add_block (void *const block, const size_type nsz, const size_type npartition_sz) |
void | add_ordered_block (void *const block, const size_type nsz, const size_type npartition_sz) |
bool | empty () const |
void *malloc | BOOST_PREVENT_MACRO_SUBSTITUTION () |
void free | BOOST_PREVENT_MACRO_SUBSTITUTION (void *const chunk) |
void | ordered_free (void *const chunk) |
void * | malloc_n (size_type n, size_type partition_size) |
Attempts to find a contiguous sequence of n partition_sz-sized chunks. More... | |
void | free_n (void *const chunks, const size_type n, const size_type partition_size) |
void | ordered_free_n (void *const chunks, const size_type n, const size_type partition_size) |
Static Public Member Functions | |
static void * | segregate (void *block, size_type nsz, size_type npartition_sz, void *end=0) |
Segregate block into chunks. More... | |
Protected Member Functions | |
void * | find_prev (void *ptr) |
Traverses the free list referred to by "first", and returns the iterator previous to where "ptr" would go if it was in the free list. More... | |
Static Protected Member Functions | |
static void *& | nextof (void *const ptr) |
Protected Attributes | |
void * | first |
This data member is the free list. More... | |
Simple Segregated Storage is the simplest, and probably the fastest, memory allocation/deallocation algorithm.
It is responsible for partitioning a memory block into fixed-size chunks: where the block comes from is determined by the client of the class.
Template class simple_segregated_storage controls access to a free list of memory chunks. Please note that this is a very simple class, with preconditions on almost all its functions. It is intended to be the fastest and smallest possible quick memory allocator - e.g., something to use in embedded systems. This class delegates many difficult preconditions to the user (i.e., alignment issues).
An object of type simple_segregated_storage<SizeType> is empty if its free list is empty. If it is not empty, then it is ordered if its free list is ordered. A free list is ordered if repeated calls to malloc()
will result in a constantly-increasing sequence of values, as determined by std::less<void *>
. A member function is order-preserving if the free list maintains its order orientation (that is, an ordered free list is still ordered after the member function call).
typedef SizeType boost::simple_segregated_storage< SizeType >::size_type |
|
inline |
Construct empty storage area.
|
inline |
Add block Segregate this block and merge its free list into the free list referred to by "first".
References BOOST_POOL_VALIDATE_INTERNALS, and boost::simple_segregated_storage< SizeType >::segregate().
Referenced by boost::simple_segregated_storage< SizeType >::add_ordered_block(), and boost::simple_segregated_storage< SizeType >::free_n().
|
inline |
add block (ordered into list) This (slower) version of add_block segregates the block and merges its free list into our free list in the proper order.
References boost::simple_segregated_storage< SizeType >::add_block(), BOOST_POOL_VALIDATE_INTERNALS, boost::simple_segregated_storage< SizeType >::find_prev(), boost::simple_segregated_storage< SizeType >::nextof(), and boost::simple_segregated_storage< SizeType >::segregate().
Referenced by boost::simple_segregated_storage< SizeType >::ordered_free_n().
|
inline |
Create a chunk.
References BOOST_POOL_VALIDATE_INTERNALS, boost::simple_segregated_storage< SizeType >::first, and boost::simple_segregated_storage< SizeType >::nextof().
|
inline |
Free a chunk.
References BOOST_POOL_VALIDATE_INTERNALS, boost::simple_segregated_storage< SizeType >::first, and boost::simple_segregated_storage< SizeType >::nextof().
|
inline |
|
protected |
Traverses the free list referred to by "first", and returns the iterator previous to where "ptr" would go if it was in the free list.
Returns 0 if "ptr" would go at the beginning of the free list (i.e., before "first").
References boost::xpressive::first.
Referenced by boost::simple_segregated_storage< SizeType >::add_ordered_block(), and boost::simple_segregated_storage< SizeType >::ordered_free().
|
inline |
References boost::simple_segregated_storage< SizeType >::add_block(), and BOOST_POOL_VALIDATE_INTERNALS.
void * boost::simple_segregated_storage< SizeType >::malloc_n | ( | size_type | n, |
size_type | partition_size | ||
) |
Attempts to find a contiguous sequence of n partition_sz-sized chunks.
If found, removes them all from the free list and returns a pointer to the first. If not found, returns 0. It is strongly recommended (but not required) that the free list be ordered, as this algorithm will fail to find a contiguous sequence unless it is contiguous in the free list as well. Order-preserving. O(N) with respect to the size of the free list.
References BOOST_POOL_VALIDATE_INTERNALS, and boost::xpressive::first.
|
inlinestaticprotected |
The return value is just *ptr cast to the appropriate type. ptr must not be 0. (For the sake of code readability :)
As an example, let us assume that we want to truncate the free list after the first chunk. That is, we want to set *first to 0; this will result in a free list with only one entry. The normal way to do this is to first cast first to a pointer to a pointer to void, and then dereference and assign (*static_cast<void **>(first) = 0;). This can be done more easily through the use of this convenience function (nextof(first) = 0;).
References boost::python::ptr().
Referenced by boost::simple_segregated_storage< SizeType >::add_ordered_block(), boost::simple_segregated_storage< SizeType >::BOOST_PREVENT_MACRO_SUBSTITUTION(), and boost::simple_segregated_storage< SizeType >::ordered_free().
|
inline |
This (slower) implementation of 'free' places the memory back in the list in its proper order.
References BOOST_POOL_VALIDATE_INTERNALS, boost::simple_segregated_storage< SizeType >::find_prev(), and boost::simple_segregated_storage< SizeType >::nextof().
|
inline |
Free n chunks from order list.
References boost::simple_segregated_storage< SizeType >::add_ordered_block(), and BOOST_POOL_VALIDATE_INTERNALS.
|
static |
Segregate block into chunks.
References boost::end.
Referenced by boost::simple_segregated_storage< SizeType >::add_block(), and boost::simple_segregated_storage< SizeType >::add_ordered_block().
|
protected |
This data member is the free list.
It points to the first chunk in the free list, or is equal to 0 if the free list is empty.
Referenced by boost::simple_segregated_storage< SizeType >::BOOST_PREVENT_MACRO_SUBSTITUTION().