2026-05-10 13:36:52 -07:00
|
|
|
// SPDX-FileCopyrightText: 2026 Erin Catto
|
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "container.h"
|
|
|
|
|
|
|
|
|
|
#include "box3d/base.h"
|
|
|
|
|
|
|
|
|
|
#define B3_BLOCK_EXPONENT 8
|
|
|
|
|
#define B3_BLOCK_SIZE ( 1 << B3_BLOCK_EXPONENT )
|
|
|
|
|
|
|
|
|
|
typedef struct b3Block
|
|
|
|
|
{
|
|
|
|
|
char* memory;
|
|
|
|
|
} b3Block;
|
|
|
|
|
|
|
|
|
|
b3DeclareArray( b3Block );
|
|
|
|
|
|
|
|
|
|
typedef struct b3BlockAllocator
|
|
|
|
|
{
|
2026-06-11 22:39:26 -07:00
|
|
|
b3Array( b3Block ) blocks;
|
2026-05-10 13:36:52 -07:00
|
|
|
void* freeList;
|
|
|
|
|
int elementSize;
|
|
|
|
|
int nextIndex;
|
|
|
|
|
int allocationCount;
|
|
|
|
|
} b3BlockAllocator;
|
|
|
|
|
|
2026-07-18 22:43:03 -07:00
|
|
|
// Element must be large enough to hold a pointer. The element size is rounded up to B3_ALIGNMENT.
|
2026-05-10 13:36:52 -07:00
|
|
|
b3BlockAllocator b3CreateBlockAllocator( int elementSize, int initialCount );
|
|
|
|
|
void b3DestroyBlockAllocator( b3BlockAllocator* allocator );
|
|
|
|
|
|
2026-06-26 21:10:10 -07:00
|
|
|
// Returns one element of elementSize contiguous bytes. Address is stable until freed.
|
2026-05-10 13:36:52 -07:00
|
|
|
void* b3AllocateElement( b3BlockAllocator* allocator );
|
|
|
|
|
void b3FreeElement( b3BlockAllocator* allocator, void* element );
|