DeepSeek-V3/experimental/src/core/memory.zig
Triex 31ef81000f feat: Migrate experimental implementation to modern Zig, achieve clean compilation (private repo dump -> /experimental)
- Port HTTP server, and appropriate points across core etc from old API to Zig `0.15.0-dev` patterns
- Fix mutability, unused variables, and API compatibility issues
- Validate SIMD tensor operations and backend architecture
- Foundation now compiles cleanly and produces working binary
2025-06-06 15:31:21 +10:00

35 lines
968 B
Zig

const std = @import("std");
const Allocator = std.mem.Allocator;
/// Arena allocator for request-scoped memory
pub const ArenaAllocator = std.heap.ArenaAllocator;
/// Memory pool for tensor allocations
pub const TensorPool = struct {
allocator: Allocator,
pool: std.ArrayList([]u8),
pub fn init(allocator: Allocator) TensorPool {
return TensorPool{
.allocator = allocator,
.pool = std.ArrayList([]u8).init(allocator),
};
}
pub fn deinit(self: *TensorPool) void {
for (self.pool.items) |buf| {
self.allocator.free(buf);
}
self.pool.deinit();
}
pub fn alloc(self: *TensorPool, size: usize) ![]u8 {
// TODO: Implement memory pooling
return try self.allocator.alloc(u8, size);
}
pub fn free(self: *TensorPool, buf: []u8) void {
// TODO: Return to pool instead of freeing
self.allocator.free(buf);
}
};