 |
CUGL 1.3
Cornell University Game Library
|
43 #ifndef __CU_FREE_LIST_H__
44 #define __CU_FREE_LIST_H__
50 #pragma mark FreeList Template
112 #pragma mark Constructors
158 CUAssertLog(capacity,
"An unexapandable free list must have non-zero capacity");
179 bool init(
size_t capacity,
bool expand) {
180 CUAssertLog(capacity || expand,
"The free list must be expandable or have capacity non-zero");
201 static std::shared_ptr<FreeList<T>>
alloc(
size_t capacity=0,
bool expand=
false) {
202 std::shared_ptr<FreeList<T>> result = std::make_shared<FreeList<T>>();
203 return (result->init(capacity,expand) ? result :
nullptr);
207 #pragma mark Accessors
268 #pragma mark Memory Managment
304 virtual void clear();
309 #pragma mark Method Implementations
324 if (!_freeobjs.empty()) {
325 result = _freeobjs.front();
328 }
else if (_allocated < _capacity) {
329 result = &_prealloc[_allocated];
331 }
else if (_expandable) {
333 _expansion.push(result);
336 _peaksize = (_peaksize < getUsage() ? getUsage() : _peaksize);
356 CUAssertLog(obj !=
nullptr,
"Attempt to free null pointer");
372 while (!_expansion.empty()) {
373 T* a = _expansion.front();
379 for(
int ii =0; ii < _capacity; ii++) {
380 _prealloc[ii].reset();
384 while (!_expansion.empty()) {
Definition: CUFreeList.h:90
size_t getUsage() const
Definition: CUFreeList.h:236
size_t _allocated
Definition: CUFreeList.h:93
size_t getPeakUsage() const
Definition: CUFreeList.h:246
bool init(size_t capacity, bool expand)
Definition: CUFreeList.h:179
bool _expandable
Definition: CUFreeList.h:108
bool isExpandable() const
Definition: CUFreeList.h:256
void dispose()
Definition: CUFreeList.h:140
size_t _released
Definition: CUFreeList.h:95
std::queue< T * > _expansion
Definition: CUFreeList.h:110
const T * getPreallocated() const
Definition: CUFreeList.h:265
T * _prealloc
Definition: CUFreeList.h:100
static std::shared_ptr< FreeList< T > > alloc(size_t capacity=0, bool expand=false)
Definition: CUFreeList.h:201
size_t getAvailable() const
Definition: CUFreeList.h:216
bool init(size_t capacity)
Definition: CUFreeList.h:157
size_t _capacity
Definition: CUFreeList.h:102
FreeList()
Definition: CUFreeList.h:122
size_t _peaksize
Definition: CUFreeList.h:97
virtual void clear()
Definition: CUFreeList.h:370
void free(T *obj)
Definition: CUFreeList.h:355
size_t getCapacity() const
Definition: CUFreeList.h:226
std::queue< T * > _freeobjs
Definition: CUFreeList.h:105
~FreeList()
Definition: CUFreeList.h:131
T * malloc()
Definition: CUFreeList.h:322