Comment

Comment by dilap

Here's another example of the coolness of Zig's comptime code execution:

https://github.com/ziglang/zig/commit/0808d98e10c5fea27cebf9...

That's a generic container class (similar to vector in C++ or List in C#). But! With a twist!

It stores structs in "column major" order in memory (e.g., if a struct had two fields A and B, then in-memory layout would be A...AB...B), and you can idiomatically and efficiently get a a slice of the values of each column.

I.e., it's a datastructure that automatically applies the struct-of-arrays optimization:

https://en.m.wikipedia.org/wiki/AoS_and_SoA#Structure_of_Arr...

And the code to do it is straightforward, normal Zig.

Pretty awesome stuff!

parent dilap 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton