spot
0.9.1
|
A multiple-size memory pool implementation. More...
#include <misc/mspool.hh>
Classes | |
struct | block_ |
union | chunk_ |
Public Member Functions | |
multiple_size_pool () | |
Create a pool. | |
~multiple_size_pool () | |
Free any memory allocated by this pool. | |
size_t | fixsize (size_t size) const |
void * | allocate (size_t size) |
Allocate size bytes of memory. | |
void | deallocate (const void *ptr, size_t size) |
Recycle size bytes of memory. | |
Private Attributes | |
Sgi::hash_map< size_t, block_ * > | freelist_ |
char * | free_start_ |
char * | free_end_ |
union spot::multiple_size_pool::chunk_ * | chunklist_ |
Static Private Attributes | |
static const size_t | alignment_ = 2 * sizeof(size_t) - 1 |
A multiple-size memory pool implementation.
spot::multiple_size_pool::multiple_size_pool | ( | ) | [inline] |
Create a pool.
spot::multiple_size_pool::~multiple_size_pool | ( | ) | [inline] |
Free any memory allocated by this pool.
References chunklist_, and spot::multiple_size_pool::chunk_::prev.
void* spot::multiple_size_pool::allocate | ( | size_t | size | ) | [inline] |
Allocate size bytes of memory.
References chunklist_, spot::multiple_size_pool::chunk_::data_, fixsize(), free_end_, free_start_, freelist_, spot::multiple_size_pool::block_::next, and spot::multiple_size_pool::chunk_::prev.
void spot::multiple_size_pool::deallocate | ( | const void * | ptr, |
size_t | size | ||
) | [inline] |
Recycle size bytes of memory.
Despite the name, the memory is not really deallocated in the "delete" sense: it is still owned by the pool and will be reused by allocate as soon as possible. The memory is only freed when the pool is destroyed.
The size argument should be the same as the one passed to allocate().
References fixsize(), freelist_, and spot::multiple_size_pool::block_::next.
size_t spot::multiple_size_pool::fixsize | ( | size_t | size | ) | const [inline] |
References alignment_.
Referenced by allocate(), and deallocate().
const size_t spot::multiple_size_pool::alignment_ = 2 * sizeof(size_t) - 1 [static, private] |
Referenced by fixsize().
union spot::multiple_size_pool::chunk_* spot::multiple_size_pool::chunklist_ [private] |
Referenced by allocate(), and ~multiple_size_pool().
char* spot::multiple_size_pool::free_end_ [private] |
Referenced by allocate().
char* spot::multiple_size_pool::free_start_ [private] |
Referenced by allocate().
Sgi::hash_map<size_t, block_*> spot::multiple_size_pool::freelist_ [private] |
Referenced by allocate(), and deallocate().