33 #ifndef __H__SMALL_OBJECT_ALLOCATOR__
34 #define __H__SMALL_OBJECT_ALLOCATOR__
45 FixedAllocator(std::size_t blockSize,
unsigned char numBlocksPerChunk);
58 void init(std::size_t blockSize,
unsigned char numBlocks);
64 void*
allocate(std::size_t blockSize);
96 template <std::
size_t maxObjSize = 64, std::
size_t maxChunkSize = 4096>
104 void*
allocate(std::size_t numBytes);
122 template <std::
size_t maxObjSize = 64, std::
size_t maxChunkSize = 4096>
126 static void*
operator new(std::size_t size);
127 static void operator delete(
void*
p, std::size_t size);
Definition: small_object_allocator.h:43
std::size_t m_numFreeBlocks
Definition: small_object_allocator.h:92
std::vector< Chunk > Chunks
Definition: small_object_allocator.h:83
unsigned char m_numBlocksPerChunk
Definition: small_object_allocator.h:87
std::size_t m_blockSize
Definition: small_object_allocator.h:86
int m_deallocChunkIndex
Definition: small_object_allocator.h:91
int m_emptyChunkIndex
Definition: small_object_allocator.h:90
void * allocate()
Definition: small_object_allocator.cpp:48
bool pointer_is_in_chunk(void *p, Chunk *chunk)
Definition: small_object_allocator.h:76
FixedAllocator(std::size_t blockSize, unsigned char numBlocksPerChunk)
Definition: small_object_allocator.cpp:37
Chunks m_chunks
Definition: small_object_allocator.h:88
Chunk * m_allocChunk
Definition: small_object_allocator.h:89
void deallocate(void *p)
Definition: small_object_allocator.cpp:78
Definition: small_object_allocator.h:98
void deallocate(void *p, std::size_t size)
make sure that size exactly specifies the number of bytes of the object to which p points.
Definition: small_object_allocator_impl.h:57
void * allocate(std::size_t numBytes)
if numBytes > maxObjSize, allocate will directly call new.
Definition: small_object_allocator_impl.h:47
static SmallObjectAllocator & inst()
returns an instance to this singleton
Definition: small_object_allocator_impl.h:39
SmallObjectAllocator()
Definition: small_object_allocator_impl.h:68
std::vector< FixedAllocator > m_allocators
Definition: small_object_allocator.h:113
Definition: small_object_allocator.h:124
virtual ~SmallObject()
Definition: small_object_allocator.h:128
Definition: small_object_allocator.h:56
void deallocate(void *p, std::size_t blockSize)
deallocates the given pointer.
Definition: small_object_allocator.cpp:178
unsigned char m_firstAvailableBlock
Definition: small_object_allocator.h:71
void * allocate(std::size_t blockSize)
returns 0 if no more blocks are available.
Definition: small_object_allocator.cpp:165
unsigned char m_numAvailableBlocks
Definition: small_object_allocator.h:72
unsigned char * m_pData
Definition: small_object_allocator.h:70
void free()
call this method instead of a destructor
Definition: small_object_allocator.cpp:159
void init(std::size_t blockSize, unsigned char numBlocks)
be careful. numBlocks has to be <= 255.
Definition: small_object_allocator.cpp:147