Allocator question

Following code does not work.
How can i modify, print content

const std = @import("std");
const deb = std.debug;
const io =;
const pri = deb.print;
const sheap = std.heap;
const config = .{ .safety = true };

pub fn main() !void {
    pri("Hello World1\n", .{});
    const a = [3]i32{ 1, 2, 3 };
    pri("{d}\n", .{a[1]});

    var b = sheap.ArenaAllocator.init(std.heap.page_allocator);
    defer b.deinit();
    const allocator = b.allocator();
    _ = try allocator.alloc(u8, 1);
    _ = try allocator.alloc(u8, 10);
    _ = try allocator.alloc(u8, 100);
    pri("{d}\n", .{b[1][1]});

I don’t think there’s a simple way to inspect an arena like that. By design, it manages a general memory region, not individual allocations.

If you want to walk up the memory of the arena allocator, you’ll have to follow the same pattern they use in the class to traverse the internal linked list:

    pub fn queryCapacity(self: ArenaAllocator) usize {
        var size: usize = 0;
        var it = self.state.buffer_list.first;
        while (it) |node| : (it = {
            // Compute the actually allocated size excluding the
            // linked list node.
            size += - @sizeOf(BufNode);
        return size;

Here, you can see that they have a while loop where they walk over every link in the chain. However, you’ll notice that they’re also subtracting some information off each time. That’s because the arena allocator creates chunks of memory and implants each node into that raw memory itself (what follows after the node is your data in each chunk). The syntax you’re using b[i][j] assumes a 2-dimentional array like structure - that won’t work for linked lists.

You’ll have to do a bit of reverse engineering to find your data in the internals of the arena allocator.