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

binarytrees/1.zig Node allocator #408

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

nomota
Copy link

@nomota nomota commented Jul 7, 2023

In this Zig code, every Node object had its own allocator. Assigning allocator to every Node object is absurd.

Removing allocator from Node struct would be a simple solution.

However simingly @hanabi1224 does not like that idea because Zig language usually assigns specific allocator to each data structure and it's fair to do so, reflecting the language's norm of its own standard library.

Fine. Zig language allows static members in struct.

So I let specific allocator still remain in Node structure, but it can be changed to be static. The allocator in Node now became static and set only once.

Assigning allocator to every Node object is absurd. Make it static, so that set only once.
@highfestiva
Copy link

Sounds reasonable.

@rolfscherer
Copy link

I think a bufferd writer is also useful:

const stdout_file = std.io.getStdOut().writer(); var bw = std.io.bufferedWriter(stdout_file); const stdout = bw.writer();

An arena allocator should also be faster when releasing memory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants