15 #include "simpleAllocator.h" 39 void SimpleAllocator::
40 output(ostream &out)
const {
42 out <<
"SimpleAllocator, " << _total_size <<
" of " << _max_size
51 void SimpleAllocator::
52 write(ostream &out)
const {
54 out <<
"SimpleAllocator, " << _total_size <<
" of " << _max_size
58 while (block->_next !=
this) {
61 out <<
" " << *block <<
"\n";
78 do_alloc(
size_t size) {
79 if (size > _contiguous) {
93 end = block->_start + block->_size;
96 while (block->_next !=
this) {
98 size_t free_size = next->_start - end;
99 if (size <= free_size) {
103 new_block->insert_before(next);
106 if (_max_size - _total_size < _contiguous) {
110 _contiguous = _max_size - _total_size;
111 changed_contiguous();
115 if (free_size > best) {
120 end = block->_start + block->_size;
125 size_t free_size = _max_size - end;
126 if (size <= free_size) {
130 new_block->insert_before(
this);
133 if (_max_size - _total_size < _contiguous) {
137 _contiguous = _max_size - _total_size;
138 changed_contiguous();
143 if (free_size > best) {
149 if (_contiguous != best) {
151 changed_contiguous();
165 make_block(
size_t start,
size_t size) {
176 void SimpleAllocator::
177 changed_contiguous() {
185 void SimpleAllocatorBlock::
186 output(ostream &out)
const {
188 out <<
"free block\n";
191 out <<
"block of size " << _size <<
" at " << _start;
An implementation of a very simple block allocator.
A lightweight C++ object whose constructor calls acquire() and whose destructor calls release() on a ...
This just stores the pointers to implement a doubly-linked list of some kind of object.
A single block as returned from SimpleAllocator::alloc().
SimpleAllocator * get_allocator() const
Returns the SimpleAllocator object that owns this block.