63 memset(m_chunks, 0, m_chunkSpace *
sizeof(
b2Chunk));
64 memset(m_freeLists, 0,
sizeof(m_freeLists));
66 if (s_blockSizeLookupInitialized ==
false)
72 if (i <= s_blockSizes[j])
74 s_blockSizeLookup[i] = (
uint8)j;
79 s_blockSizeLookup[i] = (
uint8)j;
83 s_blockSizeLookupInitialized =
true;
89 for (
int32 i = 0; i < m_chunkCount; ++i)
109 int32 index = s_blockSizeLookup[size];
112 if (m_freeLists[index])
114 b2Block* block = m_freeLists[index];
115 m_freeLists[index] = block->
next;
120 if (m_chunkCount == m_chunkSpace)
125 memcpy(m_chunks, oldChunks, m_chunkCount *
sizeof(
b2Chunk));
130 b2Chunk* chunk = m_chunks + m_chunkCount;
139 for (
int32 i = 0; i < blockCount - 1; ++i)
170 int32 index = s_blockSizeLookup[size];
177 for (
int32 i = 0; i < m_chunkCount; ++i)
196 memset(p, 0xfd, blockSize);
200 block->
next = m_freeLists[index];
201 m_freeLists[index] = block;
206 for (
int32 i = 0; i < m_chunkCount; ++i)
212 memset(m_chunks, 0, m_chunkSpace *
sizeof(
b2Chunk));
214 memset(m_freeLists, 0,
sizeof(m_freeLists));
const int32 b2_maxBlockSize
void Free(void *p, int32 size)
Free memory. This will use b2Free if the size is larger than b2_maxBlockSize.
static int32 s_blockSizes[b2_blockSizes]
static uint8 s_blockSizeLookup[b2_maxBlockSize+1]
void * Allocate(int32 size)
Allocate memory. This will use b2Alloc if the size is larger than b2_maxBlockSize.
static bool s_blockSizeLookupInitialized
const int32 b2_chunkArrayIncrement
const int32 b2_blockSizes
void * b2Alloc(int32 size)
Implement this function to use your own memory allocator.
void b2Free(void *mem)
If you implement b2Alloc, you should also implement this function.