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

@@ -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;
}
}