▲ | quotemstr 3 days ago | ||||||||||||||||||||||
Zig articles tend to get a little too excited about rediscovering longstanding techniques. The author has described a metaprogramming utility for allocating a contiguous hunk of memory, carving this hunk into fields (in the article's example, a fixed-sized Client header, then some number of bytes for host, then some number of bytes for read_buffer, and then some for write_buffer). I'll acknowledge the syntax is convenient, but 1. we've done this since time immemorial in C. See https://learn.microsoft.com/en-us/windows/win32/api/evntcons... 2. you can implement this pattern ergonomically in C++, and even moreso once the C++26 reflection stuff comes online 3. the zig implementation is inefficient. It desugars to
That first pointer is needless indirection and probably a cache miss. You should (unless you have specific performance data showing otherwise) store the sizes in the object header, not in an obese pointer to it. (It's bigger than even a fat pointer.) | |||||||||||||||||||||||
▲ | rvrb 3 days ago | parent | next [-] | ||||||||||||||||||||||
You have raised a good discussion point or two, but I am not inclined to engage with them due to the tone you've created with the rest of your comment. Would it be productive to jump into a thread on a Ruby article and puff your feathers about how you've always been able to do this in Perl, and also in Python 4 you can do XYZ? I don't think so. For whatever reason, inevitably in threads on systems languages, someone comes in and postures themselves defensively like this. You might want to reflect on that. | |||||||||||||||||||||||
| |||||||||||||||||||||||
▲ | AndyKelley 3 days ago | parent | prev [-] | ||||||||||||||||||||||
I think you're misinterpreting OP's excitement here. The technique isn't novel but the ergonomics are. > you can implement this pattern ergonomically in C++, lmao | |||||||||||||||||||||||
|