4 ms·
Zig uses manual memory management too (even more manual than Rust), so that's a bit strange question.
by sanxiyn 5y ago
Zig uses manual memory management too (even more manual than Rust), so that's a bit strange question.
- cercatrova 5y agoInteresting, based on their code samples it looked to me like a GC language since (at least from what I saw) I didn't see anything regarding memory management.
- sanxiyn 5y agoI am not sure what code samples you looked at, but https://ziglearn.org/chapter-2/ https://ziglearn.org/chapter-2/ should give you an idea.
- elcritch 5y agoIt’s easy, IMHO, to mistake Zig as a GC’ed language or more broadly as a memory safe systems language. It’s neither but it is a nicer C.
- zigger69 5y agoIt's really easy in Zig to be honest. Just put `defer thing.deinit()` in the right scope and you're done. You gain explicitness and know exactly what's going on in your Code. Everything is obvious. That's the reason Zig is so incredible simple and easy to read. Zig also has a GPA that will tell you about memory leaks or anything.
- puffoflogic 5y agoAnd in rust you just put `` in the right scope and you're done. This is perfectly explicit and you know exactly what's going on in your code. Everything is obvious.
- zigger69 5y agoYou can execute arbitrary code on drop operations by implementing `std::ops::Drop` for a type.
- pornel 5y agoA `.deinit()` function could also run some arbitrary code that does weird and unexpected things. The point is that reasonable people don't abuse functions like that — if they do abuse, don't use their code. Neither Rust nor Zig is a sandbox that could stop actively stupid/malicious code.
- dralley 5y agoRust's ownership rules are no less explicit. The object dies when the owner of the data goes out of scope.