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

@@ -108,10 +108,10 @@ Array :: struct {
add :: (self: *Array, v: Value, alloc: Allocator) {
if self.len >= self.cap {
new_cap := if self.cap == 0 then 4 else self.cap * 2;
new_items : [*]Value = xx alloc.alloc(new_cap * size_of(Value));
new_items : [*]Value = xx alloc.alloc_bytes(new_cap * size_of(Value));
if self.len > 0 {
memcpy(new_items, self.items, self.len * size_of(Value));
alloc.dealloc(self.items);
alloc.dealloc_bytes(self.items);
}
self.items = new_items;
self.cap = new_cap;
@@ -121,7 +121,7 @@ Array :: struct {
}
deinit :: (self: *Array, alloc: Allocator) {
if self.items != null { alloc.dealloc(self.items); }
if self.items != null { alloc.dealloc_bytes(self.items); }
self.items = null;
self.len = 0;
self.cap = 0;
@@ -142,10 +142,10 @@ Object :: struct {
put :: (self: *Object, key: string, v: Value, alloc: Allocator) {
if self.len >= self.cap {
new_cap := if self.cap == 0 then 4 else self.cap * 2;
new_items : [*]Member = xx alloc.alloc(new_cap * size_of(Member));
new_items : [*]Member = xx alloc.alloc_bytes(new_cap * size_of(Member));
if self.len > 0 {
memcpy(new_items, self.items, self.len * size_of(Member));
alloc.dealloc(self.items);
alloc.dealloc_bytes(self.items);
}
self.items = new_items;
self.cap = new_cap;
@@ -155,7 +155,7 @@ Object :: struct {
}
deinit :: (self: *Object, alloc: Allocator) {
if self.items != null { alloc.dealloc(self.items); }
if self.items != null { alloc.dealloc_bytes(self.items); }
self.items = null;
self.len = 0;
self.cap = 0;
@@ -538,7 +538,7 @@ Parser :: struct {
return string.{ ptr = @self.src[start], len = end - start };
}
raw_len := end - start; // decoded length <= raw_len (escapes shrink)
out : [*]u8 = xx self.alloc.alloc(raw_len);
out : [*]u8 = xx self.alloc.alloc_bytes(raw_len);
dlen := try self.decode_into(start, end, out);
self.pos = end + 1;
return string.{ ptr = out, len = dlen };

View File

@@ -11,10 +11,10 @@
CAllocator :: struct {}
impl Allocator for CAllocator {
alloc :: (self: *CAllocator, size: s64) -> *void {
alloc_bytes :: (self: *CAllocator, size: s64) -> *void {
return libc_malloc(size);
}
dealloc :: (self: *CAllocator, ptr: *void) {
dealloc_bytes :: (self: *CAllocator, ptr: *void) {
libc_free(ptr);
}
}
@@ -40,11 +40,11 @@ GPA :: struct {
}
impl Allocator for GPA {
alloc :: (self: *GPA, size: s64) -> *void {
alloc_bytes :: (self: *GPA, size: s64) -> *void {
self.alloc_count += 1;
return libc_malloc(size);
}
dealloc :: (self: *GPA, ptr: *void) {
dealloc_bytes :: (self: *GPA, ptr: *void) {
self.alloc_count -= 1;
libc_free(ptr);
}
@@ -78,7 +78,7 @@ Arena :: struct {
prev_cap := if a.first != null then a.first.cap else 0;
needed := min_size + 16 + 16;
len := (prev_cap + needed) * 3 / 2;
raw := a.parent.alloc(len);
raw := a.parent.alloc_bytes(len);
chunk : *ArenaChunk = xx raw;
chunk.next = a.first;
chunk.cap = len;
@@ -97,7 +97,7 @@ Arena :: struct {
it := a.first.next;
while it != null {
next := it.next;
a.parent.dealloc(it);
a.parent.dealloc_bytes(it);
it = next;
}
a.first.next = null;
@@ -109,7 +109,7 @@ Arena :: struct {
it := a.first;
while it != null {
next := it.next;
a.parent.dealloc(it);
a.parent.dealloc_bytes(it);
it = next;
}
a.first = null;
@@ -118,7 +118,7 @@ Arena :: struct {
}
impl Allocator for Arena {
alloc :: (self: *Arena, size: s64) -> *void {
alloc_bytes :: (self: *Arena, size: s64) -> *void {
aligned := (size + 7) & (0 - 8);
if self.first != null {
usable := self.first.cap - 16;
@@ -135,7 +135,7 @@ impl Allocator for Arena {
self.end_index = self.end_index + aligned;
ptr
}
dealloc :: (self: *Arena, ptr: *void) {}
dealloc_bytes :: (self: *Arena, ptr: *void) {}
}
// --- BufAlloc: bump allocator backed by a user-provided slice ---
@@ -167,7 +167,7 @@ BufAlloc :: struct {
}
impl Allocator for BufAlloc {
alloc :: (self: *BufAlloc, size: s64) -> *void {
alloc_bytes :: (self: *BufAlloc, size: s64) -> *void {
aligned := (size + 7) & (0 - 8);
if self.pos + aligned > self.len {
return null;
@@ -176,7 +176,7 @@ impl Allocator for BufAlloc {
self.pos = self.pos + aligned;
ptr
}
dealloc :: (self: *BufAlloc, ptr: *void) {}
dealloc_bytes :: (self: *BufAlloc, ptr: *void) {}
}
// --- TrackingAllocator: wraps any Allocator, counts allocs/deallocs ---
@@ -228,16 +228,16 @@ TrackingAllocator :: struct {
}
impl Allocator for TrackingAllocator {
alloc :: (self: *TrackingAllocator, size: s64) -> *void {
ptr := self.parent.alloc(size);
alloc_bytes :: (self: *TrackingAllocator, size: s64) -> *void {
ptr := self.parent.alloc_bytes(size);
if ptr != null {
self.alloc_count += 1;
self.total_alloc_bytes += size;
}
ptr
}
dealloc :: (self: *TrackingAllocator, ptr: *void) {
self.parent.dealloc(ptr);
dealloc_bytes :: (self: *TrackingAllocator, ptr: *void) {
self.parent.dealloc_bytes(ptr);
self.dealloc_count += 1;
}
}