-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
229 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-FileCopyrightText: 2023 Erin Catto | ||
// SPDX-License-Identifier: MIT | ||
|
||
#pragma once | ||
|
||
#include "array.h" | ||
|
||
B2_ARRAY_DECLARE( b2ArenaEntry, b2ArenaEntry ); | ||
|
||
// This is a stack-like arena allocator used for fast per step allocations. | ||
// You must nest allocate/free pairs. The code will B2_ASSERT | ||
// if you try to interleave multiple allocate/free pairs. | ||
// This allocator uses the heap if space is insufficient. | ||
// I could remove the need to free entries individually. | ||
typedef struct b2ArenaAllocator | ||
{ | ||
char* data; | ||
int capacity; | ||
int index; | ||
|
||
int allocation; | ||
int maxAllocation; | ||
|
||
b2ArenaEntryArray entries; | ||
} b2ArenaAllocator; | ||
|
||
b2ArenaAllocator b2CreateArenaAllocator( int capacity ); | ||
void b2DestroyArenaAllocator( b2ArenaAllocator* allocator ); | ||
|
||
void* b2AllocateArenaItem( b2ArenaAllocator* alloc, int size, const char* name ); | ||
void b2FreeArenaItem( b2ArenaAllocator* alloc, void* mem ); | ||
|
||
// Grow the arena based on usage | ||
void b2GrowArena( b2ArenaAllocator* alloc ); | ||
|
||
int b2GetArenaCapacity( b2ArenaAllocator* alloc ); | ||
int b2GetArenaAllocation( b2ArenaAllocator* alloc ); | ||
int b2GetMaxArenaAllocation( b2ArenaAllocator* alloc ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.