aboutsummaryrefslogtreecommitdiff
path: root/include/base/memory.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/base/memory.h')
-rw-r--r--include/base/memory.h24
1 files changed, 13 insertions, 11 deletions
diff --git a/include/base/memory.h b/include/base/memory.h
index dd00992..767e948 100644
--- a/include/base/memory.h
+++ b/include/base/memory.h
@@ -21,6 +21,7 @@ typedef struct mem·BufHead
byte buf[];
} mem·BufHead;
+#define mem·buffer(x) x*
#define mem·bufhdr(b) ((mem·BufHead*)((uint8*)(b)-offsetof(mem·BufHead, buf)))
#define mem·buflen(b) ((b) ? (mem·bufhdr(b)->len) : 0)
#define mem·bufcap(b) ((b) ? (mem·bufhdr(b)->cap) : 0)
@@ -44,26 +45,27 @@ void* mem·bufgrow(void*, vlong, vlong);
// memory allocation
/* interfaces */
+typedef struct mem·Pool mem·Pool;
+typedef struct mem·Arena mem·Arena;
+
typedef struct mem·Allocator {
void *(*alloc)(void *heap, uint n, ulong size);
+ void *(*realloc)(void *iface, void *ptr, uint n, ulong size);
void (*free)(void *heap, void *ptr);
} mem·Allocator;
-extern mem·Allocator sys·Memory;
+extern mem·Allocator base·Memory; /* standard allocator */
-typedef struct mem·Reallocator {
- void *(*alloc)(void *iface, uint n, ulong size);
- void *(*realloc)(void *iface, void *ptr, uint n, ulong size);
- void (*free)(void *iface, void *ptr);
-} mem·Reallocator;
+/* pool allocator (manages free list) */
+mem·Pool *mem·makepool(mem·Allocator from, void*);
+void mem·freepool(mem·Pool);
-extern mem·Reallocator sys·FullMemory;
-
-/* simple memory arena */
-typedef struct mem·Arena mem·Arena;
+void *mem·poolalloc(mem·Pool *, uintptr n, uintptr size);
+void *mem·poolrealloc(mem·Pool *, void *, uintptr n, uintptr size);
+void mem·poolfree(mem·Pool *, void *);
+/* simple arena allocator (heterogeneous bump) */
mem·Arena *mem·makearena(mem·Allocator from, void*);
void *mem·arenaalloc(mem·Arena *A, uint n, ulong size);
void mem·freearena(mem·Arena *A);
-
extern mem·Allocator mem·ArenaAllocator;