Implement null allocator
This commit is contained in:
parent
f99e1eab67
commit
1ab9bba9da
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue