Add an implementation of Zig's Allocator interface (#94)
This commit is contained in:
parent
b5330624d6
commit
39909cdcb3
4 changed files with 184 additions and 0 deletions
|
|
@ -1437,3 +1437,27 @@ pub fn textJoin(textList: [][:0]const u8, delimiter: [:0]const u8) [:0]const u8
|
|||
pub fn drawTriangleStrip3D(points: []Vector3, color: Color) void {
|
||||
cdef.DrawTriangleStrip3D(@as([*c]Vector3, @ptrCast(points)), @as(c_int, @intCast(points.len)), color);
|
||||
}
|
||||
|
||||
fn alloc(_: *anyopaque, len: usize, _: u8, _: usize) ?[*]u8 {
|
||||
std.debug.assert(len > 0);
|
||||
return @ptrCast(cdef.MemAlloc(@intCast(len)));
|
||||
}
|
||||
|
||||
fn resize(_: *anyopaque, buf: []u8, _: u8, new_len: usize, _: usize) bool {
|
||||
return (new_len <= buf.len);
|
||||
}
|
||||
|
||||
fn free(_: *anyopaque, buf: []u8, _: u8, _: usize) void {
|
||||
cdef.MemFree(buf.ptr);
|
||||
}
|
||||
|
||||
const mem_vtable = std.mem.Allocator.VTable{
|
||||
.alloc = alloc,
|
||||
.resize = resize,
|
||||
.free = free,
|
||||
};
|
||||
|
||||
pub const mem = std.mem.Allocator{
|
||||
.ptr = undefined,
|
||||
.vtable = &mem_vtable,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue