Created
July 30, 2020 10:05
-
-
Save lithdew/d01ab5beec771c8e51c29c66465842e8 to your computer and use it in GitHub Desktop.
zig: stack alloc recursive data structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const Node = struct { | |
left: ?*Node = null, | |
right: ?*Node = null, | |
pub fn new(allocator: *std.mem.Allocator) !Node { | |
return Node{ | |
.left = try allocator.create(Node), | |
.right = try allocator.create(Node), | |
}; | |
} | |
}; | |
pub fn main() !void { | |
var buf: [65536]u8 = undefined; | |
var buffer = std.heap.FixedBufferAllocator.init(&buf); | |
var node = try Node.new(&buffer.allocator); | |
std.debug.print("{}\n", .{node}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment