-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnull_allocator.zig
More file actions
65 lines (57 loc) · 1.26 KB
/
null_allocator.zig
File metadata and controls
65 lines (57 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// The NullAllocator is meant to be used as a fallback
// for allocator composition.
// For example, a StackAllocator, if it runs out of memory,
// can dispatch to another allocator to fulfill the request.
// If we want that to signal an error, we can give it the
// NullAllocator as a fallback and that will signal an
// "OutOfMemory" error, enforcing that we don't ask for
// more memory than is on the stack.
const std = @import("std");
const Self = @This();
pub fn allocator() std.mem.Allocator {
return .{
.ptr = undefined,
.vtable = &.{
.alloc = alloc,
.resize = resize,
.free = free,
},
};
}
fn alloc(
ctx: *anyopaque,
len: usize,
log2_ptr_align: u8,
ret_addr: usize
) ?[*]u8 {
_ = ret_addr;
_ = log2_ptr_align;
_ = len;
_ = ctx;
return null;
}
fn resize(
ctx: *anyopaque,
old_mem: []u8,
log2_align: u8,
new_len: usize,
ret_addr: usize,
) bool {
_ = ret_addr;
_ = new_len;
_ = log2_align;
_ = old_mem;
_ = ctx;
return false;
}
fn free(
ctx: *anyopaque,
old_mem: []u8,
log2_align: u8,
ret_addr: usize,
) void {
_ = ret_addr;
_ = log2_align;
_ = old_mem;
_ = ctx;
}