Files
ci2/include/platform/mem/ci2_arena.h
T

56 lines
1.9 KiB
C
Raw Normal View History

2026-06-06 18:15:42 -05:00
/* - | Copyright | ------------------------------------------------------------
2026-06-06 18:22:23 -05:00
Copyright (c) 2026 Randy Jordan
2026-06-06 18:15:42 -05:00
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
* --------------------------------------------------------------------------*/
#ifndef CI2_ARENA_H
#define CI2_ARENA_H
2026-06-06 18:22:23 -05:00
#include <stddef.h>
2026-06-06 18:15:42 -05:00
struct Arena
{
2026-06-06 18:22:23 -05:00
char* beg;
char* end;
2026-06-06 18:15:42 -05:00
};
typedef struct Arena Arena;
2026-06-06 18:22:23 -05:00
/* Initialize an Arena with an existing buffer */
extern void
arena_back(struct Arena* a, char* buf, ptrdiff_t len);
2026-06-06 18:15:42 -05:00
2026-06-06 18:22:23 -05:00
/* Allocate a new Arena */
extern struct Arena
2026-06-06 18:15:42 -05:00
arena_new(ptrdiff_t cap);
2026-06-06 18:22:23 -05:00
/* Get the current capacity of an Arena */
extern ptrdiff_t
arena_capacity(struct Arena a);
/* Make an allocation from an Arena and do not zero.*/
extern void*
arena_malloc(struct Arena* a, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
2026-06-06 18:15:42 -05:00
2026-06-06 18:22:23 -05:00
/* Make an allocation from an Arena and zero.*/
extern void*
arena_calloc(struct Arena* a, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
2026-06-06 18:15:42 -05:00
#endif // ci2_arena.h