Nori

OrderedChunkAllocator Class Reference

Special "ordered" memory allocator. More...

#include <gkdtree.h>

List of all members.

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.

Detailed Description

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.

Author:
Wenzel Jakob

Definition at line 81 of file gkdtree.h.


Constructor & Destructor Documentation

OrderedChunkAllocator::OrderedChunkAllocator ( size_t  minAllocation = NORI_KD_MIN_ALLOC) [inline]

Definition at line 83 of file gkdtree.h.

OrderedChunkAllocator::~OrderedChunkAllocator ( ) [inline]

Definition at line 88 of file gkdtree.h.


Member Function Documentation

template<typename T >
T* OrderedChunkAllocator::allocate ( size_t  size) [inline]

Request a block of memory from the allocator.

Walks through the list of chunks to find one with enough free memory. If no chunk could be found, a new one is created.

Definition at line 126 of file gkdtree.h.

void OrderedChunkAllocator::cleanup ( ) [inline]

Release all memory used by the allocator.

Definition at line 95 of file gkdtree.h.

void OrderedChunkAllocator::forget ( ) [inline]

Forget about all chunks without actually freeing them. This is useful when the chunks have been merged into another allocator.

Definition at line 116 of file gkdtree.h.

size_t OrderedChunkAllocator::getChunkCount ( ) const [inline]

Definition at line 179 of file gkdtree.h.

void OrderedChunkAllocator::merge ( const OrderedChunkAllocator other) [inline]

Merge the chunks of another allocator into this one.

Definition at line 105 of file gkdtree.h.

template<typename T >
void OrderedChunkAllocator::release ( T *  ptr) [inline]

Definition at line 151 of file gkdtree.h.

template<typename T >
void OrderedChunkAllocator::shrinkAllocation ( T *  ptr,
size_t  newSize 
) [inline]

Shrink the size of the last allocated chunk.

Definition at line 166 of file gkdtree.h.

size_t OrderedChunkAllocator::size ( ) const [inline]

Return the total amount of chunk memory in bytes.

Definition at line 184 of file gkdtree.h.

size_t OrderedChunkAllocator::used ( ) const [inline]

Return the total amount of used memory in bytes.

Definition at line 195 of file gkdtree.h.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines