Go to the documentation of this file.
32 Size totalSize, totalUsed;
40 Size totalSize, totalUsed;
43 assert(totalUsed <= totalSize);
45 return totalSize - totalUsed;
76 totalSize +=
sizeof(
Pool);
77 totalSize += pool->bitmapSize;
78 totalSize += pool->size();
80 totalUsed +=
sizeof(
Pool);
81 totalUsed += pool->bitmapSize;
82 totalUsed += (pool->size() - pool->available());
97 else if (inputSize == 0)
153 Result result = prefix->pool->release(actualAddr);
157 if (prefix->pool->available() == prefix->pool->size())
168 Size index, nPools = 1, objectSize = 0;
176 if (requestedSize <= objectSize)
181 if (requestedSize > objectSize)
194 for (pool =
m_pools[index]; pool; pool = pool->
next, nPools++)
201 else if (!pool->
next)
215 const Size requestBitmapSize = objectCount;
216 const Size requestPayloadSize = objectCount * objectSize;
217 const Size requestTotalSize =
aligned(
sizeof(
Pool) + requestBitmapSize + requestPayloadSize,
sizeof(
u32));
224 alloc_args.
size = requestTotalSize;
236 Size actualObjectCount = (alloc_args.
size -
sizeof(
Pool) - requestBitmapSize) / objectSize;
237 Size actualPayloadSize = 0;
238 Size actualBitmapSize = 0;
239 Size actualTotalSize = 0;
241 assert(actualObjectCount >= objectCount);
243 while (actualObjectCount >= objectCount)
245 actualPayloadSize = actualObjectCount * objectSize;
246 actualBitmapSize =
aligned(actualObjectCount,
sizeof(
u32));
247 actualTotalSize =
sizeof(
Pool) + actualBitmapSize + actualPayloadSize;
249 if (actualTotalSize <= alloc_args.
size)
257 const Allocator::Range range = { bitmapAddr + actualBitmapSize, actualPayloadSize,
sizeof(
u32) };
260 pool =
new (alloc_args.
address)
Pool(range, objectSize, actualBitmapSize, (
u8 *) bitmapAddr);
282 if (prevPool !=
NULL)
284 prevPool->
next = nextPool;
287 if (nextPool !=
NULL)
289 nextPool->
prev = prevPool;
Size index
Index number in the m_pools array where this Pool is stored.
Pool * m_pools[MaximumPoolSize+1]
Array of memory pools.
virtual Size size() const
Get memory size.
Pool * allocatePool(const uint index, const Size objectCount)
Creates a new Pool instance.
static void * set(void *dest, int ch, unsigned count)
Fill memory with a constant byte.
u32 signature
Filled with a fixed value to detect corruption/overflows.
u32 signature
Filled with a fixed value to detect corruption/overflows.
static const u32 ObjectSignature
Signature value is used to detect object corruption/overflows.
This data structure is prepended in memory before each object.
Pool * prev
Points to the previous pool of this size (if any).
unsigned long Address
A memory address.
Allocates same-sized objects from a contiguous block of memory.
Address address
Starting address of the memory range.
Size calculateObjectCount(const Size objectSize) const
Calculate minimum object count for a Pool.
Appended in memory after each object.
Size alignment
Alignment in bytes or ZERO for default alignment.
static const Size MinimumPoolSize
Minimum power of two for a pool size.
Pool * next
Points to the next pool of this size (if any).
virtual Size available() const
Get available memory.
Size size
Amount of memory in bytes.
PoolAllocator::Pool Pool
Allocates same-sized objects from a contiguous block of memory.
static const Size MaximumPoolSize
Maximum power of two size a pool can be (128MiB).
struct PoolAllocator::ObjectPrefix ObjectPrefix
This data structure is prepended in memory before each object.
Size calculateObjectSize(const Size index) const
Calculate object size given the Pool index number.
virtual Size available() const
Get memory available.
#define KiloByte(v)
Convert kilobytes to bytes.
Allocator * parent()
Get parent Allocator.
#define NULL
NULL means zero.
virtual Result allocate(Range &range)
Allocate memory.
unsigned int u32
Unsigned 32-bit number.
unsigned int Size
Any sane size indicator cannot go negative.
Result releasePool(Pool *pool)
Release Pool instance memory.
Pool * pool
Points to the Pool instance where this object belongs to.
Pool * retrievePool(const Size inputSize)
Find a Pool of sufficient size.
PoolAllocator(Allocator *parent)
Constructor.
Describes a range of memory.
void calculateUsage(Size &totalSize, Size &totalUsed) const
Determine total memory usage.
#define assert(exp)
Insert program diagnostics.
virtual Result release(const Address addr)
Release memory.
unsigned char u8
Unsigned 8-bit number.
void setParent(Allocator *parent)
Set parent allocator.
bool isPowerOfTwo(unsigned number)
Check if a number is power of two.
virtual Result release(const Address addr)
Release memory.
virtual Result allocate(Range &args)
Allocate memory.
Result
Allocation results.
Address aligned(const Address addr, const Size boundary) const
Align memory address.