21 INLINE SimpleAllocator::
22 SimpleAllocator(
size_t max_size,
Mutex &lock) :
26 _contiguous(max_size),
43 return do_alloc(size);
129 INLINE
bool SimpleAllocator::
130 do_is_empty()
const {
131 return (_next ==
this);
143 INLINE
void SimpleAllocator::
157 if (space > _contiguous) {
159 changed_contiguous();
169 INLINE SimpleAllocatorBlock::
171 size_t start,
size_t size) :
258 return do_get_max_size();
272 return do_realloc(size);
295 INLINE
void SimpleAllocatorBlock::
299 _allocator->_total_size -= _size;
302 _allocator->mark_contiguous(prev);
314 INLINE
size_t SimpleAllocatorBlock::
315 do_get_max_size()
const {
317 if (_next == _allocator) {
318 end = _allocator->_max_size;
334 INLINE
bool SimpleAllocatorBlock::
335 do_realloc(
size_t size) {
336 if (size > do_get_max_size()) {
340 _allocator->_total_size -= _size;
341 _allocator->_total_size += size;
346 _allocator->mark_contiguous(
this);
~SimpleAllocatorBlock()
The block automatically frees itself when it destructs.
An implementation of a very simple block allocator.
size_t get_contiguous() const
Returns an upper-bound estimate of the size of the largest contiguous block that may be allocated...
bool is_empty() const
Returns true if there are no blocks allocated on this page, or false if there is at least one...
SimpleAllocatorBlock * alloc(size_t size)
Allocates a new block.
SimpleAllocatorBlock * get_first_block() const
Returns a pointer to the first allocated block, or NULL if there are no allocated blocks...
A standard mutex, or mutual exclusion lock.
A lightweight C++ object whose constructor calls acquire() and whose destructor calls release() on a ...
bool realloc(size_t size)
Changes the size of this block to the specified size.
This just stores the pointers to implement a doubly-linked list of some kind of object.
A single block as returned from SimpleAllocator::alloc().
size_t get_start() const
Returns the starting point of this block.
size_t get_max_size() const
Returns the maximum size this block can be reallocated to, as limited by the following block...
size_t get_total_size() const
Returns the total size of allocated objects.
void free()
Releases the allocated space.
bool is_free() const
Returns true if the block has been freed, false if it is still valid.
size_t get_size() const
Returns the size of this block.
size_t get_max_size() const
Returns the available space for allocated objects.
SimpleAllocatorBlock * get_next_block() const
Returns a pointer to the next allocated block in the chain, or NULL if there are no more allocated bl...
SimpleAllocator * get_allocator() const
Returns the SimpleAllocator object that owns this block.
void set_max_size(size_t max_size)
Changes the available space for allocated objects.