Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.heap.ArenaAllocator should attempt to resize before allocating a new node #5116

Closed
andrewrk opened this issue Apr 21, 2020 · 0 comments · Fixed by #6413
Closed

std.heap.ArenaAllocator should attempt to resize before allocating a new node #5116

andrewrk opened this issue Apr 21, 2020 · 0 comments · Fixed by #6413
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. enhancement Solving this issue will likely involve adding new logic or components to the codebase. optimization standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@andrewrk
Copy link
Member

Currently ArenaAllocator does this:

            const cur_buf = cur_node.data[@sizeOf(BufNode)..];
            const addr = @ptrToInt(cur_buf.ptr) + self.end_index;
            const adjusted_addr = mem.alignForward(addr, alignment);
            const adjusted_index = self.end_index + (adjusted_addr - addr);
            const new_end_index = adjusted_index + n;
            if (new_end_index > cur_buf.len) {
                cur_node = try self.createNode(cur_buf.len, n + alignment);
                continue;
            }

After #4431 is implemented, this can be improved to attempt a resize before creating a new allocation. This will make it OK to use an ArenaAllocator as the backing allocator of an ArenaAllocator when it is the newest allocation.

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. optimization standard library This issue involves writing Zig code for the standard library. labels Apr 21, 2020
@andrewrk andrewrk added this to the 0.7.0 milestone Apr 21, 2020
LemonBoy added a commit to LemonBoy/zig that referenced this issue Sep 24, 2020
LemonBoy added a commit to LemonBoy/zig that referenced this issue Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. enhancement Solving this issue will likely involve adding new logic or components to the codebase. optimization standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant