mem: rename Allocator primitives to alloc_bytes/dealloc_bytes (Phase 4 naming pulled forward, Agra-approved)

This commit is contained in:
agra
2026-06-11 15:33:35 +03:00
parent ca5bd52262
commit 88bae3c9f5
58 changed files with 1536 additions and 1534 deletions

View File

@@ -40,9 +40,11 @@ string :: []u8 #builtin;
// --- Allocator protocol (impls live in std/mem.sx) ---
// Bytes-level primitives carry the `_bytes` suffix so the typed
// helpers in std/mem.sx own the bare names (`alloc(T, n)`, `free(s)`).
Allocator :: protocol #inline {
alloc :: (size: s64) -> *void;
dealloc :: (ptr: *void);
alloc_bytes :: (size: s64) -> *void;
dealloc_bytes :: (ptr: *void);
}
// --- Context ---
@@ -55,7 +57,7 @@ Context :: struct {
// --- Slice & string allocation ---
cstring :: (size: s64) -> string {
raw := context.allocator.alloc(size + 1);
raw := context.allocator.alloc_bytes(size + 1);
memset(raw, 0, size + 1);
s : string = ---;
s.ptr = xx raw;
@@ -64,7 +66,7 @@ cstring :: (size: s64) -> string {
}
alloc_slice :: ($T: Type, count: s64) -> []T {
raw := context.allocator.alloc(count * size_of(T));
raw := context.allocator.alloc_bytes(count * size_of(T));
memset(raw, 0, count * size_of(T));
s : []T = ---;
s.ptr = xx raw;
@@ -456,10 +458,10 @@ List :: struct ($T: Type) {
append :: (list: *List(T), item: T, alloc: Allocator = context.allocator) {
if list.len >= list.cap {
new_cap := if list.cap == 0 then 4 else list.cap * 2;
new_items : [*]T = xx alloc.alloc(new_cap * size_of(T));
new_items : [*]T = xx alloc.alloc_bytes(new_cap * size_of(T));
if list.len > 0 {
memcpy(new_items, list.items, list.len * size_of(T));
alloc.dealloc(list.items);
alloc.dealloc_bytes(list.items);
}
list.items = new_items;
list.cap = new_cap;
@@ -472,10 +474,10 @@ List :: struct ($T: Type) {
if list.cap >= n { return; }
new_cap := if list.cap == 0 then 4 else list.cap;
while new_cap < n { new_cap = new_cap * 2; }
new_items : [*]T = xx alloc.alloc(new_cap * size_of(T));
new_items : [*]T = xx alloc.alloc_bytes(new_cap * size_of(T));
if list.len > 0 {
memcpy(new_items, list.items, list.len * size_of(T));
alloc.dealloc(list.items);
alloc.dealloc_bytes(list.items);
}
list.items = new_items;
list.cap = new_cap;
@@ -483,7 +485,7 @@ List :: struct ($T: Type) {
deinit :: (list: *List(T), alloc: Allocator = context.allocator) {
if list.items != null {
alloc.dealloc(list.items);
alloc.dealloc_bytes(list.items);
}
list.items = null;
list.len = 0;