Programming-Language-Benchmarks icon indicating copy to clipboard operation
Programming-Language-Benchmarks copied to clipboard

binarytrees/1.zig Node allocator

Open nomota opened this issue 2 years ago • 5 comments

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.

nomota avatar Jul 07 '23 04:07 nomota

Sounds reasonable.

highfestiva avatar Jul 13 '23 08:07 highfestiva

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

rolfscherer avatar Aug 07 '23 11:08 rolfscherer

This is unfair to assign allocator to each node.

ivanstepanovftw avatar Jul 28 '24 15:07 ivanstepanovftw