box3d/samples/gfx/arena.h
Erin Catto 9e02b7f3b3
New sample renderer and UI (#10)
No changes to simulation
2026-06-06 10:06:05 -07:00

37 lines
891 B
C

// SPDX-FileCopyrightText: 2026 Erin Catto
// SPDX-License-Identifier: MIT
#pragma once
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct Arena
{
uint8_t* base; // owned heap allocation, capacity bytes
size_t capacity;
size_t used;
} Arena;
// Returns 0 on success, -1 on allocation failure. capacity must be > 0.
int ArenaInit( Arena* a, size_t capacity );
// Free backing storage. Safe on a zero-initialized arena.
void ArenaShutdown( Arena* a );
// Bump-allocate `size` bytes with `align` alignment (must be power-of-two).
// Returns NULL if the request would overflow the arena, logs to stderr.
void* ArenaAlloc( Arena* a, size_t size, size_t align );
// Reset to empty without freeing backing storage. Invalidates all
// pointers handed out before the reset.
void ArenaReset( Arena* a );
#ifdef __cplusplus
} // extern "C"
#endif