This commit is contained in:
agra
2026-02-20 23:18:17 +02:00
parent efa60fa670
commit be99b26c1d
5 changed files with 127 additions and 27 deletions

View File

@@ -31,8 +31,12 @@ context : Context = ---;
// --- Slice & string allocation ---
context_alloc :: (size: s64) -> *void {
if context.allocator.ctx != null then context.allocator.alloc(size) else malloc(size);
}
cstring :: (size: s64) -> string {
raw := if context.allocator.ctx != null then context.allocator.alloc(context.allocator.ctx, size + 1) else malloc(size + 1);
raw := context_alloc(size + 1);
memset(raw, 0, size + 1);
s : string = ---;
s.ptr = xx raw;
@@ -41,7 +45,7 @@ cstring :: (size: s64) -> string {
}
alloc_slice :: ($T: Type, count: s64) -> []T {
raw := if context.allocator.ctx != null then context.allocator.alloc(context.allocator.ctx, count * size_of(T)) else malloc(count * size_of(T));
raw := context_alloc(count * size_of(T));
memset(raw, 0, count * size_of(T));
s : []T = ---;
s.ptr = xx raw;