4 ms·
BetterC is not no GC mode, BetterC was made to make sharing D code easier with C GC only exist if you call ``new MyThing`` Just use your allocators with mallo
by Shadonototra 4y ago
BetterC is not no GC mode, BetterC was made to make sharing D code easier with C
GC only exist if you call ``new MyThing``
Just use your allocators with malloc/free, that is what i do (you do the same in zig, allocators)
if you want to enforce no GC use in your APIs, there is the @nogc attribute you can use
- OskarS 4y ago> Just use your allocators with malloc/free, that is what i do (you do the same in zig, allocators) If you do that, is it RAII like C++/Rust? Objects get destructed at end of scope, and members get destructed recursively? Or do you have to manually call `free()` on everything? (which, granted, is significantly easier in languages with `defer` mechanisms)
- nicwilson 4y agoRAII, though there is also `scope(exit)`
- WalterBright 4y agoYes, it is RAII and RAII is fully implemented in D.
- alphaglosined 4y agoBut only for structs. We really need to get actual reference counting into the language to cover classes properly as well. It has been on my todo list to write a DIP for this for a while now. ~rikki.
- ntrel 4y agoClass instances can go on the stack too using `scope`: scope obj = new Object; ... // destroyed at end of scope
- Shadonototra 4y agoD has defer scope(exit): scope(failure): scope(success): https://tour.dlang.org/tour/en/gems/scope-guards https://tour.dlang.org/tour/en/gems/scope-guards You can do RAII with D too, it's your choice, based on your use case