Allocgate: Restructuring how allocators work in Zig
pithlessly.github.io
Allocgate: Restructuring how allocators work in Zig
1–10 of 52 posts
Re: Allocgate: Restructuring how allocators work in Zig
#2Re: Allocgate: Restructuring how allocators work in Zig
#3Re: Allocgate: Restructuring how allocators work in Zig
#4Does anyone know if RAII types will ever be a thing in Zig?
Re: Allocgate: Restructuring how allocators work in Zig
#5Does anyone know if RAII types will ever be a thing in Zig?
For now the the closest thing to RAII is this proposal, but there is no guarantee that it will be accepted.
Re: Allocgate: Restructuring how allocators work in Zig
#6Does anyone know if RAII types will ever be a thing in Zig?
`defer` and `errdefer` give you 90% of what destructors & co give you for 0% of the complexity. For now the the closest thing to RAII is this proposal, but there is no guarantee that it will be accepted. https://github.com/ziglang/zig/issues/782
https://en.cppreference.com/w/cpp/language/rule_of_three
C++ RAII also rubs up painfully against handle based APIs (looking at you Windows) in my experience. There is a lack of standardized RAII wrappers for handle types like there is for pointers. Yes you can pull in a custom handle RAII wrapper but at that point it's simpler to just manage manually.
Defer on the other hand is simple. Anyone can understand it in five minutes.
Re: Allocgate: Restructuring how allocators work in Zig
#7Re: Allocgate: Restructuring how allocators work in Zig
#8Does anyone know if RAII types will ever be a thing in Zig?
Examples:
[1]: https://news.ycombinator.com/item?id=29506814
[2]: https://gist.github.com/andrewrk/190170bc1441839644c3f15725a...
Re: Allocgate: Restructuring how allocators work in Zig
#9Does anyone know if RAII types will ever be a thing in Zig?
`defer` and `errdefer` give you 90% of what destructors & co give you for 0% of the complexity. For now the the closest thing to RAII is this proposal, but there is no guarantee that it will be accepted. https://github.com/ziglang/zig/issues/782
Re: Allocgate: Restructuring how allocators work in Zig
#10Does anyone know if RAII types will ever be a thing in Zig?
- constructors
- destructors
- overloadable copy assignment operators
- placement new
- move semantics and rvalue references
These features come together or not at all. If you lose any of them, the language becomes less complete. I think Rust and C++ are doing a fine job of exploring the design space of languages that have this feature set, but it's too much complexity for Zig.
Edit: As commenters have pointed out, this exact manifestation of these features is not required. A more correct set of requirements is:
- a notion of beginning and ending object lifetimes in existing memory
- a notion of move semantics to relocate an existing RAII object
- a notion of non-copyability for certain types, or an ability to override copy behavior