Nori
|
Special "ordered" memory allocator. More...
#include <gkdtree.h>
Classes | |
struct | Chunk |
Public Member Functions | |
OrderedChunkAllocator (size_t minAllocation=NORI_KD_MIN_ALLOC) | |
~OrderedChunkAllocator () | |
void | cleanup () |
Release all memory used by the allocator. | |
void | merge (const OrderedChunkAllocator &other) |
Merge the chunks of another allocator into this one. | |
void | forget () |
Forget about all chunks without actually freeing them. This is useful when the chunks have been merged into another allocator. | |
template<typename T > | |
T * | allocate (size_t size) |
Request a block of memory from the allocator. | |
template<typename T > | |
void | release (T *ptr) |
template<typename T > | |
void | shrinkAllocation (T *ptr, size_t newSize) |
Shrink the size of the last allocated chunk. | |
size_t | getChunkCount () const |
size_t | size () const |
Return the total amount of chunk memory in bytes. | |
size_t | used () const |
Return the total amount of used memory in bytes. |
Special "ordered" memory allocator.
During kd-tree construction, large amounts of memory are required to temporarily hold index and edge event lists. When not implemented properly, these allocations can become a critical bottleneck. The class OrderedChunkAllocator provides a specialized memory allocator, which reserves memory in chunks of at least 128KiB. An important assumption made by the allocator is that memory will be released in the exact same order, in which it was previously allocated. This makes it possible to create an implementation with a very low memory overhead. Note that no locking is done, hence each thread will need its own allocator.
OrderedChunkAllocator::OrderedChunkAllocator | ( | size_t | minAllocation = NORI_KD_MIN_ALLOC | ) | [inline] |
T* OrderedChunkAllocator::allocate | ( | size_t | size | ) | [inline] |
void OrderedChunkAllocator::cleanup | ( | ) | [inline] |
void OrderedChunkAllocator::forget | ( | ) | [inline] |
size_t OrderedChunkAllocator::getChunkCount | ( | ) | const [inline] |
void OrderedChunkAllocator::merge | ( | const OrderedChunkAllocator & | other | ) | [inline] |
void OrderedChunkAllocator::release | ( | T * | ptr | ) | [inline] |
void OrderedChunkAllocator::shrinkAllocation | ( | T * | ptr, |
size_t | newSize | ||
) | [inline] |
size_t OrderedChunkAllocator::size | ( | ) | const [inline] |
size_t OrderedChunkAllocator::used | ( | ) | const [inline] |