Question about ArenaAllocator's implementation

In ArenaAllocator’s createNode function here

    fn createNode(self: *ArenaAllocator, prev_len: usize, minimum_size: usize) ?*BufNode {
        // what does this + 16 mean?
        const actual_min_size = minimum_size + (@sizeOf(BufNode) + 16);
        const big_enough_len = prev_len + actual_min_size;
        const len = big_enough_len + big_enough_len / 2;
        const ptr = self.child_allocator.rawAlloc(len, BufNode_alignment, @returnAddress()) orelse
            return null;
        const buf_node: *BufNode = @ptrCast(@alignCast(ptr));
        buf_node.* = .{ .data = len };
        self.state.buffer_list.prepend(&buf_node.node);
        self.state.end_index = 0;
        return buf_node;
    }


What does the +16 mean in the first line when computing actual_min_size?

1 Like

It seems to be just a magic number which @andrewrk observed improved performance of arena. small bump to ArenaAllocator minimum alloc size · ziglang/zig@ad4b591 · GitHub

4 Likes