initial commit
This commit is contained in:
parent
81af403965
commit
573e1a9fa3
220 changed files with 150440 additions and 0 deletions
44
src/block_allocator.h
Normal file
44
src/block_allocator.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// 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
|
||||
{
|
||||
b3ArrayC( b3Block ) blocks;
|
||||
void* freeList;
|
||||
int elementSize;
|
||||
int nextIndex;
|
||||
int allocationCount;
|
||||
} b3BlockAllocator;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
// Element must be large enough to hold a pointer
|
||||
b3BlockAllocator b3CreateBlockAllocator( int elementSize, int initialCount );
|
||||
void b3DestroyBlockAllocator( b3BlockAllocator* allocator );
|
||||
|
||||
// Elements are guaranteed contiguous.
|
||||
void* b3AllocateElement( b3BlockAllocator* allocator );
|
||||
void b3FreeElement( b3BlockAllocator* allocator, void* element );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Loading…
Reference in a new issue