This commit is contained in:
2026-06-10 07:54:03 -05:00
parent 8f85b33696
commit 65790e883f
6 changed files with 303 additions and 27 deletions
+14 -8
View File
@@ -25,31 +25,37 @@ SOFTWARE.
#include <stddef.h>
struct Arena
struct CI2_Arena
{
char* beg;
char* end;
};
typedef struct Arena Arena;
typedef struct CI2_Arena CI2_Arena;
/* Initialize an Arena with an existing buffer */
extern void
arena_back(struct Arena* a, char* buf, ptrdiff_t len);
ci2_arena_back(struct CI2_Arena* a, char* buf, ptrdiff_t len);
/* Allocate a new Arena */
extern struct Arena
arena_new(ptrdiff_t cap);
extern struct CI2_Arena
ci2_arena_new(ptrdiff_t cap);
/* Get the current capacity of an Arena */
extern ptrdiff_t
arena_capacity(struct Arena a);
ci2_arena_capacity(struct CI2_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);
ci2_arena_malloc(struct CI2_Arena* a,
ptrdiff_t size,
ptrdiff_t align,
ptrdiff_t count);
/* Make an allocation from an Arena and zero.*/
extern void*
arena_calloc(struct Arena* a, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
ci2_arena_calloc(struct CI2_Arena* a,
ptrdiff_t size,
ptrdiff_t align,
ptrdiff_t count);
#endif // ci2_arena.h
+12 -12
View File
@@ -1,5 +1,5 @@
/* - | Copyright | ------------------------------------------------------------
Copyright (c) 2026 Randy Jordan
Copyright (c) 2026 Randy Jordan
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
@@ -36,10 +36,10 @@ ci2_malloc(size_t nbytes, const char* file, const char* func, int line);
/* Allocate an object and zero ci2ory. May throw exception. */
CI2_API void*
ci2_calloc(size_t count,
size_t nbytes,
const char* file,
const char* func,
int line);
size_t nbytes,
const char* file,
const char* func,
int line);
/* Free and null a pointer */
CI2_API void
@@ -48,22 +48,22 @@ ci2_free(void** ptr, const char* file, const char* func, int line);
/* Resize a non-null pointer */
CI2_API void*
ci2_resize(void* ptr,
size_t nbytes,
const char* file,
const char* func,
int line);
size_t nbytes,
const char* file,
const char* func,
int line);
#define CI2_MALLOC(nbytes) ci2_malloc((nbytes), __FILE__, CI2_FUNC, __LINE__)
#define CI2_CALLOC(count, nbytes) \
ci2_calloc((count), (nbytes), __FILE__, CI2_FUNC, __LINE__)
ci2_calloc((count), (nbytes), __FILE__, CI2_FUNC, __LINE__)
#define CI2_NEW(p) ((p) = CI2_MALLOC((size_t)sizeof *(p)))
#define CI2_NEW0(p) ((p) = CI2_CALLOC(1, (size_t)sizeof *(p)))
#define CI2_FREE(ptr) \
((void)(ci2_free((ptr), __FILE__, CI2_FUNC, __LINE__), (ptr) = 0))
((void)(ci2_free((ptr), __FILE__, CI2_FUNC, __LINE__), (ptr) = 0))
#define CI2_RESIZE(ptr, nbytes) \
((ptr) = ci2_resize((ptr), (nbytes), __FILE__, CI2_FUNC, __LINE__))
((ptr) = ci2_resize((ptr), (nbytes), __FILE__, CI2_FUNC, __LINE__))
#endif // ci2_mem.h