-
-
Save fengb/1bcf4e784ebfff337d1a02edd646412b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const FreeList = linked_list.SinglyLinkedList([]u8); | |
fn consumeUnusedNode(self: *Self) !*FreeList.Node { | |
if (self.unused_nodes.first == null) { | |
// var bytes = try self.backing_allocator.alignedAlloc(u8, page_size, self.page_size); | |
var bytes = try self.backing_allocator.reallocFn(self.backing_allocator, []u8{}, 1, self.page_size, page_size); | |
const node_memsize = bytes.len - (bytes.len % @sizeOf(FreeList.Node)); | |
// Small leak due to misalignment. Can't do anything about it... | |
bytes = bytes[0..node_memsize]; | |
const buffer = @bytesToSlice(FreeList.Node, bytes); | |
std.debug.assert(buffer.len > 0); | |
for (buffer) |*node| { | |
self.unused_nodes.prepend(node); // this breaks | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment