I knew it's not the point of the article, but would AI be any better at translating code to zig? Or would it make the same slow design, just with all the allocations being explicit?
Bloomberg writes all of its C++ using an allocator aware version of the STL because of this issue. It’s open source and very high quality: https://github.com/bloomberg/bde
What do you mean by "allocator-aware version of the STL"? The standard STL is also allocator-aware, and its containers have versions with a template allocator parameter and a polymorphic allocator.
https://bloomberg.github.io/bde/white_papers/unleashing-aa-s...
lakos was one of the primary drivers of this
That is correct. However at Bloomberg all functions that potentially allocate memory have to have an allocator passed as an argument or use a local allocator since the BDE requires allocator parameters to always be passed, there are no default allocator arguments like in the STL.
“It’s all about the Pentiums, baby”
Oh, wow, this is a fantastic explanation for why “Zig makes you pass the allocator around as an argument to all your functions” is A Good Thing, Actually. Kudos to the author!
This argues for dynamically scoped variables - bindings that are scoped and inherited by all called functions without having to be passed explicitly. After all, why should everyone in the call chain need to know if some deep call allocates temporary storage.
It's always bothered me that the only such feature in many languages is exception handlers (I'm also bothereed by functions that throw things).
I want "late" bindings, implemented as "shallow" bindings. "Late" as in binding is established at runtime in the call chain. "Shallow" as in you don't need to crawl the call chain to find it. Something like
extern Allocater *theAllocater = &DefaultAllocater;
...
// allocater scope
{ Allocater *prev = theAllocater;
theAllocater = NewAllocater();
...
theAllocater->free();
theAllocater = prev;
}
with a deep call using the current allocater // deep call
{ tmp = theAllocater->alloc(size);
...
}> So, if you want to write truly memory-efficient code, just asking AI to do it for you might not be enough.
In hindsight, it would be pretty funny if "hey can you rewrite this game in Rust" is sufficient instructions to end up with memory-efficient code. In fact it would be pretty funny if it were enough to get this thing written in Rust, for all the specific details of what you actually mean when you say "this game"