Replaced arena

This commit is contained in:
2026-06-06 18:22:23 -05:00
parent 7c1b0ab290
commit 8f85b33696
2 changed files with 62 additions and 69 deletions
+19 -31
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
@@ -23,45 +23,33 @@ SOFTWARE.
#ifndef CI2_ARENA_H
#define CI2_ARENA_H
#include "../ci2_platform.h"
#include "../error/ci2_exception.h"
enum
{
DEFAULT = 0, /* default: fail-handler (throws) + zero */
SOFT_FAIL = 1u << 0, /* on failure return NULL */
HARD_FAIL = 1u << 1, /* on failure call abort() */
NO_ZERO = 1u << 2, /* do not zero memory on success */
};
#include <stddef.h>
struct Arena
{
char* beg;
char* end;
char* beg;
char* end;
};
typedef struct Arena Arena;
/* Forward definition of an exception */
CI2_API struct Exception arena_oom;
/* Initialize an Arena with an existing buffer */
extern void
arena_back(struct Arena* a, char* buf, ptrdiff_t len);
/* Initialize an Arena from a buffer. */
CI2_API void
arena_init(struct Arena* a, void* buf, ptrdiff_t len);
/* Dynamically allocate an Arena */
CI2_API struct Arena
/* Allocate a new Arena */
extern struct Arena
arena_new(ptrdiff_t cap);
/* Get the remaining capicity of an arena. */
CI2_API ptrdiff_t
arena_size(struct Arena a);
/* Get the current capacity of an Arena */
extern ptrdiff_t
arena_capacity(struct Arena a);
/* Make an allocation from an Arena. */
CI2_API void*
arena_alloc(struct Arena* a,
int flags,
ptrdiff_t size,
ptrdiff_t align,
ptrdiff_t count);
/* 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);
/* Make an allocation from an Arena and zero.*/
extern void*
arena_calloc(struct Arena* a, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count);
#endif // ci2_arena.h