summaryrefslogtreecommitdiff
path: root/src/std
diff options
context:
space:
mode:
authorOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-05-03 21:37:51 +1000
committerOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-05-03 21:37:51 +1000
commitaed7d1b7ac340c19656059c9cbd94aff40952f83 (patch)
tree9629cfda30456200e2496d0ac706de0002927614 /src/std
parent8407723dfc12d302f6b696f702a5ae9caaf219c1 (diff)
create logical device
Diffstat (limited to 'src/std')
-rw-r--r--src/std/buf.h6
-rw-r--r--src/std/mem.c9
-rw-r--r--src/std/mem.h7
3 files changed, 18 insertions, 4 deletions
diff --git a/src/std/buf.h b/src/std/buf.h
index b0f8b85..de093ec 100644
--- a/src/std/buf.h
+++ b/src/std/buf.h
@@ -1,12 +1,12 @@
/**
* @file buf.h
* @author your name (you@domain.com)
- * @brief
+ * @brief
* @version 0.1
* @date 2024-04-28
- *
+ *
* @copyright Copyright (c) 2024
- *
+ *
*/
#pragma once
#include "defines.h"
diff --git a/src/std/mem.c b/src/std/mem.c
index 5468898..4886d72 100644
--- a/src/std/mem.c
+++ b/src/std/mem.c
@@ -31,4 +31,11 @@ void arena_free_all(arena* a) {
a->curr = a->begin; // pop everything at once and reset to the start.
}
-void arena_free_storage(arena* a) { free(a->begin); } \ No newline at end of file
+void arena_free_storage(arena* a) { free(a->begin); }
+
+arena_save arena_savepoint(arena* a) {
+ arena_save savept = { .arena = a, .savepoint = a->curr };
+ return savept;
+}
+
+void arena_rewind(arena_save savepoint) { savepoint.arena->curr = savepoint.savepoint; } \ No newline at end of file
diff --git a/src/std/mem.h b/src/std/mem.h
index 2f92894..bbfb852 100644
--- a/src/std/mem.h
+++ b/src/std/mem.h
@@ -18,9 +18,16 @@ typedef struct arena {
char* end;
} arena;
+typedef struct arena_save {
+ arena* arena;
+ char* savepoint;
+} arena_save;
+
arena arena_create(void* backing_buffer, size_t capacity);
void* arena_alloc(arena* a, size_t size);
void* arena_alloc_align(arena* a, size_t size, size_t align);
void arena_free_all(arena* a);
void arena_free_storage(arena* a);
+arena_save arena_savepoint(arena* a);
+void arena_rewind(arena_save savepoint);
// TODO: arena_resize \ No newline at end of file