Initial commit
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
/* - | Copyright | ------------------------------------------------------------
|
||||
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
|
||||
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
|
||||
|
||||
#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 */
|
||||
};
|
||||
|
||||
struct Arena
|
||||
{
|
||||
char* beg;
|
||||
char* end;
|
||||
};
|
||||
typedef struct Arena Arena;
|
||||
|
||||
/* Forward definition of an exception */
|
||||
CI2_API struct Exception arena_oom;
|
||||
|
||||
/* 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
|
||||
arena_new(ptrdiff_t cap);
|
||||
|
||||
/* Get the remaining capicity of an arena. */
|
||||
CI2_API ptrdiff_t
|
||||
arena_size(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);
|
||||
|
||||
#endif // ci2_arena.h
|
||||
Reference in New Issue
Block a user