22 _total_size(from._total_size),
23 _max_size(from._max_size),
24 _contiguous(from._contiguous),
38 while (next !=
this) {
40 nassertv(block->_allocator == &from);
41 block->_allocator =
this;
56 nassertv(_next !=
nullptr);
65 void SimpleAllocator::
66 output(std::ostream &out)
const {
68 out <<
"SimpleAllocator, " << _total_size <<
" of " << _max_size
75 void SimpleAllocator::
76 write(std::ostream &out)
const {
78 out <<
"SimpleAllocator, " << _total_size <<
" of " << _max_size
82 while (block->_next !=
this) {
85 out <<
" " << *block <<
"\n";
100 do_alloc(
size_t size,
size_t alignment) {
101 if (size > _contiguous) {
115 end = block->_start + block->_size;
118 while (block->_next !=
this) {
120 size_t start = end + ((alignment - end) % alignment);
121 if (start + size <= next->_start) {
125 new_block->insert_before(next);
128 if (_max_size - _total_size < _contiguous) {
132 _contiguous = _max_size - _total_size;
133 changed_contiguous();
137 size_t free_size = next->_start - end;
138 if (free_size > best) {
143 end = block->_start + block->_size;
148 size_t start = end + ((alignment - end) % alignment);
149 if (start + size <= _max_size) {
153 new_block->insert_before(
this);
156 if (_max_size - _total_size < _contiguous) {
160 _contiguous = _max_size - _total_size;
161 changed_contiguous();
166 size_t free_size = _max_size - end;
167 if (free_size > best) {
173 if (_contiguous != best) {
175 changed_contiguous();
187 make_block(
size_t start,
size_t size) {
196 void SimpleAllocator::
197 changed_contiguous() {
203 void SimpleAllocatorBlock::
204 output(std::ostream &out)
const {
205 if (_allocator ==
nullptr) {
206 out <<
"free block\n";
209 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().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
SimpleAllocator * get_allocator() const
Returns the SimpleAllocator object that owns this block.