33#ifndef __H__SMALL_OBJECT_ALLOCATOR_IMPL__
34#define __H__SMALL_OBJECT_ALLOCATOR_IMPL__
36template <std::
size_t maxObjSize, std::
size_t maxChunkSize>
45template <std::
size_t maxObjSize, std::
size_t maxChunkSize>
49 if(numBytes > maxObjSize)
50 return new unsigned char[numBytes];
52 return m_allocators[numBytes].
allocate();
55template <std::
size_t maxObjSize, std::
size_t maxChunkSize>
60 delete[]
static_cast<unsigned char*
>(
p);
62 m_allocators[size].deallocate(
p);
66template <std::
size_t maxObjSize, std::
size_t maxChunkSize>
71 for(std::size_t i = 0; i <= maxObjSize; ++i){
72 std::size_t maxNumBlocks = maxChunkSize / maxObjSize;
73 if(maxNumBlocks > 255)
76 static_cast<unsigned char>(maxNumBlocks)));
81template <std::
size_t maxObjSize, std::
size_t maxChunkSize>
83operator
new(std::size_t size)
88template <std::
size_t maxObjSize, std::
size_t maxChunkSize>
90operator
delete(
void*
p, std::size_t size)
Definition small_object_allocator.h:43
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
Definition small_object_allocator.h:124