22#ifndef COMMON_MEMORYPOOL_H
23#define COMMON_MEMORYPOOL_H
25#include "common/scummsys.h"
26#include "common/array.h"
59 const size_t _chunkSize;
62 size_t _chunksPerPage;
65 void addPageToPool(
const Page &page);
66 bool isPointerInPage(
void *ptr,
const Page &page);
111template<
size_t CHUNK_SIZE,
size_t NUM_INTERNAL_CHUNKS = 32>
115 REAL_CHUNK_SIZE = (CHUNK_SIZE +
sizeof(
void *) - 1) & (~(
sizeof(
void *) - 1))
118 byte _storage[NUM_INTERNAL_CHUNKS * REAL_CHUNK_SIZE];
121 assert(REAL_CHUNK_SIZE == _chunkSize);
123 Page internalPage = { _storage, NUM_INTERNAL_CHUNKS };
124 addPageToPool(internalPage);
133template<
size_t CHUNK_SIZE>
142template<
class T,
size_t NUM_INTERNAL_CHUNKS = 32>
168 assert(nbytes <= pool.getChunkSize());
169 return pool.allocChunk();
Definition: memorypool.h:112
Definition: memorypool.h:49
void freeChunk(void *ptr)
MemoryPool(size_t chunkSize)
size_t getChunkSize() const
Definition: memorypool.h:103
Definition: memorypool.h:143
void deleteChunk(T *ptr)
Definition: memorypool.h:149
Definition: algorithm.h:29
Definition: memorypool.h:54