box3d/src/block_allocator.h
Erin Catto 79fc55976a
Optimizations (#168)
- Optimize contact prepare
- Back to post restitution stage
- Optimize solver math
- Bug fixes
2026-09-24 12:21:17 -07:00

36 lines
937 B
C

// 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 )
#define B3_BLOCK_ALIGNMENT 16
typedef struct b3Block
{
char* memory;
} b3Block;
b3DeclareArray( b3Block );
typedef struct b3BlockAllocator
{
b3Array( b3Block ) blocks;
void* freeList;
int elementSize;
int nextIndex;
int allocationCount;
} b3BlockAllocator;
// Element must be large enough to hold a pointer. The element size is rounded up to B3_BLOCK_ALIGNMENT.
b3BlockAllocator b3CreateBlockAllocator( int elementSize, int initialCount );
void b3DestroyBlockAllocator( b3BlockAllocator* allocator );
// Returns one element of elementSize contiguous bytes. Address is stable until freed.
void* b3AllocateElement( b3BlockAllocator* allocator );
void b3FreeElement( b3BlockAllocator* allocator, void* element );