Implement null allocator

This commit is contained in:
kayomn 2023-05-07 14:51:22 +01:00
parent f99e1eab67
commit 1ab9bba9da
1 changed files with 11 additions and 2 deletions

View File

@ -164,13 +164,22 @@ pub fn equals(this: []const u8, that: []const u8) bool {
var null_context = @as(usize, 0);
pub const null_allocator = Allocator.bind(&null_context, struct {
fn reallocate(context: *usize, options: AllocationOptions) ?[]u8 {
debug.assert(context.* == 0);
debug.assert(options.allocation == null);
return null;
}
});
pub const null_writer = Writer.bind(&null_context, struct {
pub fn write(context: *usize, buffer: []const u8) usize {
fn write(context: *usize, buffer: []const u8) usize {
debug.assert(context.* == 0);
return buffer.len;
}
});
}.write);
pub fn overlaps(pointer: [*]u8, memory_range: []u8) bool {
return (pointer >= memory_range.ptr) and (pointer < (memory_range.ptr + memory_range.len));