4 ms·
Note that lazy-static does not "statically allocate a buffer" for all definitions of "statically allocate": lazy-static computes it's value on first use, and mu
by codys 9y ago
Note that lazy-static does not "statically allocate a buffer" for all definitions of "statically allocate": lazy-static computes it's value on first use, and must use dynamic alloc space (ie: malloc/box)
Also, lazy-static has been around for a long time. Releases first occurred in 2014! I'd be surprised if it had not been considered.
- bascule 9y agoWell, their original stated problem was just invoking size_of() at runtime, which lazy-static solves. That said, Rust supports custom allocators now: https://doc.rust-lang.org/book/custom-allocators.html https://doc.rust-lang.org/book/custom-allocators.html Write your own allocator and use Box.
- rkangel 9y agoI think you misunderstand what 'statically allocate' means. That means a size known at compile time, so that the space for that variable can be assigned in the memory map of the executable. Anything involving a 'custom allocator' is doing runtime memory allocation.
- kibwen 9y ago> Releases first occurred in 2014! I'd be surprised if it had not been considered. I wouldn't be surprised if it hadn't been considered. The paper was released in 2015, so development may have begun in 2014. Furthermore, I don't believe the authors were engaged with the broader Rust community before this paper was released (they are today), so it's possible that there was no expert there to advise them about this approach. Also, discoverability of libraries was more of an issue back then, so it's plausible that they wouldn't have found it independently.