97 memset(m_chunks, 0, m_chunkSpace *
sizeof(
b2Chunk));
98 memset(m_freeLists, 0,
sizeof(m_freeLists));
103 for (
int32 i = 0; i < m_chunkCount; ++i)
105 b2Free(m_chunks[i].blocks);
128 if (m_freeLists[index])
130 b2Block* block = m_freeLists[index];
131 m_freeLists[index] = block->
next;
136 if (m_chunkCount == m_chunkSpace)
141 memcpy(m_chunks, oldChunks, m_chunkCount *
sizeof(
b2Chunk));
146 b2Chunk* chunk = m_chunks + m_chunkCount;
155 for (
int32 i = 0; i < blockCount - 1; ++i)
162 last->
next =
nullptr;
193 for (
int32 i = 0; i < m_chunkCount; ++i)
212 memset(p, 0xfd, blockSize);
216 block->
next = m_freeLists[index];
217 m_freeLists[index] = block;
222 for (
int32 i = 0; i < m_chunkCount; ++i)
224 b2Free(m_chunks[i].blocks);
228 memset(m_chunks, 0, m_chunkSpace *
sizeof(
b2Chunk));
229 memset(m_freeLists, 0,
sizeof(m_freeLists));
void * b2Alloc(int32 size)
Implement this function to use your own memory allocator.
const int32 b2_blockSizeCount
static const int32 b2_blockSizes[b2_blockSizeCount]
static const int32 b2_chunkSize
uint8 values[b2_maxBlockSize+1]
static 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 const int32 b2_chunkArrayIncrement
void * Allocate(int32 size)
Allocate memory. This will use b2Alloc if the size is larger than b2_maxBlockSize.
static const b2SizeMap b2_sizeMap
void b2Free(void *mem)
If you implement b2Alloc, you should also implement this function.