#include <ArrayAllocator.h>
Collaboration diagram for PLearn::ArrayAllocator< T, SizeBits >:
Public Types | |
typedef ArrayAllocator< T, SizeBits > | self_type |
typedef T | value_type |
typedef unsigned | index_base |
typedef ArrayAllocatorIndex< index_base, SizeBits > | index_type |
typedef size_t | size_type |
typedef ptrdiff_t | difference_type |
typedef T * | pointer |
typedef const T * | const_pointer |
typedef T & | reference |
typedef const T & | const_reference |
Public Member Functions | |
ArrayAllocator (const ArrayAllocatorOptions &) | |
pointer | allocate (size_t n) |
default copy constructor, destructor, assignment operator Allocate N objects of type T and return a (memory) pointer to it | |
void | deallocate (pointer p, size_type n) |
Deallocate given pointer/size, or given index only. | |
void | deallocate (index_type) |
void | resize (size_type NewMaxObjs) |
size_type | max_size () const |
index_type | toIndex (pointer p, size_type n) |
Index/pointer conversion. | |
pointer | toPointer (index_type) |
void | swap (self_type &) |
Private Member Functions | |
index_type & | derefIndex (index_type i) |
Small utility. | |
index_type & | derefIndex (unsigned i) |
Private Attributes | |
vector< T > | arr |
index_type | free_root |
ArrayAllocatorOptions | options |
Furthermore, the maximum number of objects that can be stored (in bits) is 8 * sizeof(index_base) - SizeBits, where 8*sizeof(index_base) is usually 32 for most computers. Hence, if arrays of a maximum size of 256 elements are to be stored (8 bits), then only 16777216 elements can be allocated.
Internally, index number 0 is reserved to denote a null pointer, and not otherwise used in the array.
The free list is represented as follows: the variable free_root represents the index of the first free block (the size field of free_root is not used). In the memory location at that index, we assume that we have an index_type structure (instead of a T), and this index_type contains two things: the index of the next free block (or zero if none), along with the size of the current free block.
Definition at line 137 of file ArrayAllocator.h.
|
Definition at line 148 of file ArrayAllocator.h. |
|
Definition at line 150 of file ArrayAllocator.h. |
|
Definition at line 145 of file ArrayAllocator.h. |
|
Definition at line 142 of file ArrayAllocator.h. |
|
Definition at line 143 of file ArrayAllocator.h. |
|
Definition at line 147 of file ArrayAllocator.h. Referenced by PLearn::ArrayAllocator< T, SizeBits >::allocate(). |
|
Definition at line 149 of file ArrayAllocator.h. |
|
Definition at line 140 of file ArrayAllocator.h. |
|
Definition at line 144 of file ArrayAllocator.h. Referenced by PLearn::ArrayAllocator< T, SizeBits >::max_size(). |
|
Definition at line 141 of file ArrayAllocator.h. |
|
Definition at line 196 of file ArrayAllocator.h. References PLearn::ArrayAllocatorOptions::numObjs, PLearn::ArrayAllocator< T, SizeBits >::options, and resize(). |
|
default copy constructor, destructor, assignment operator Allocate N objects of type T and return a (memory) pointer to it < could not allocate Take a look at the block pointed to by free_pointer, and if it's big enough, take a chunk from the BEGINNING, and modify *free_pointer to point to the next correct free block Definition at line 237 of file ArrayAllocator.h. References PLearn::ArrayAllocator< T, SizeBits >::derefIndex(), PLearn::ArrayAllocator< T, SizeBits >::free_root, if(), PLearn::ArrayAllocatorIndex< IndexBase, SizeBits >::index, PLearn::ArrayAllocatorIndex< IndexBase, SizeBits >::isNull(), PLERROR, PLearn::ArrayAllocator< T, SizeBits >::pointer, PLearn::ArrayAllocatorIndex< IndexBase, SizeBits >::size, and PLearn::ArrayAllocator< T, SizeBits >::toPointer(). |
|
The current code is frankly not too object-oriented... Null deallocator: do nothing Not implemented yet... Unsorted deallocator: just add block to free list; don't collapse adjacent free blocks Definition at line 280 of file ArrayAllocator.h. References PLearn::ArrayAllocatorOptions::deallocatorType, PLearn::ArrayAllocator< T, SizeBits >::derefIndex(), PLearn::ArrayAllocator< T, SizeBits >::free_root, PLearn::ArrayAllocatorIndex< IndexBase, SizeBits >::index, PLearn::ArrayAllocatorIndex< IndexBase, SizeBits >::isNull(), PLearn::ArrayAllocator< T, SizeBits >::options, PLERROR, and PLearn::ArrayAllocatorIndex< IndexBase, SizeBits >::size. |
|
Deallocate given pointer/size, or given index only.
Definition at line 273 of file ArrayAllocator.h. References PLearn::ArrayAllocator< T, SizeBits >::deallocate(). Referenced by PLearn::ArrayAllocator< T, SizeBits >::deallocate(). |
|
Definition at line 181 of file ArrayAllocator.h. References PLearn::ArrayAllocator< T, SizeBits >::arr. |
|
|
Definition at line 164 of file ArrayAllocator.h. References PLearn::ArrayAllocator< T, SizeBits >::arr, and PLearn::ArrayAllocator< T, SizeBits >::size_type. |
|
zero is not a valid starting index Since the maximum block size is limited to SizeBits, we cannot create a single big new free region with the new objects; instead, we must create several free regions of maximum size and link them together in the free list. Definition at line 204 of file ArrayAllocator.h. References PLearn::ArrayAllocator< T, SizeBits >::arr, PLearn::ArrayAllocator< T, SizeBits >::derefIndex(), PLearn::ArrayAllocator< T, SizeBits >::free_root, PLearn::ArrayAllocatorIndex< IndexBase, SizeBits >::index, PLearn::max(), PLearn::min(), and PLearn::ArrayAllocatorIndex< IndexBase, SizeBits >::size. |
|
Definition at line 329 of file ArrayAllocator.h. References PLearn::ArrayAllocator< T, SizeBits >::arr, PLearn::ArrayAllocator< T, SizeBits >::free_root, and PLearn::swap(). |
|
Index/pointer conversion.
Definition at line 308 of file ArrayAllocator.h. References PLearn::ArrayAllocator< T, SizeBits >::arr. |
|
Definition at line 319 of file ArrayAllocator.h. References PLearn::ArrayAllocator< T, SizeBits >::arr, PLearn::ArrayAllocatorIndex< IndexBase, SizeBits >::index, and PLearn::ArrayAllocatorIndex< IndexBase, SizeBits >::isNull(). Referenced by PLearn::ArrayAllocator< T, SizeBits >::allocate(). |
|
|
Definition at line 187 of file ArrayAllocator.h. Referenced by PLearn::ArrayAllocator< T, SizeBits >::allocate(), PLearn::ArrayAllocator< T, SizeBits >::deallocate(), PLearn::ArrayAllocator< T, SizeBits >::resize(), and PLearn::ArrayAllocator< T, SizeBits >::swap(). |
|
Definition at line 188 of file ArrayAllocator.h. Referenced by PLearn::ArrayAllocator< T, SizeBits >::ArrayAllocator(), and PLearn::ArrayAllocator< T, SizeBits >::deallocate(). |