5 ms·
Boy, I can't wait for theangeryemacsshibe (posts here as hayley-patton) to tear into this one. But yeah, the correct way to handle resources (not just memory!)
by bitwize 4y ago
Boy, I can't wait for theangeryemacsshibe (posts here as hayley-patton) to tear into this one.
But yeah, the correct way to handle resources (not just memory!) is with value semantics and RAII. Because then you know the object will be cleaned up as soon as it goes out of scope with zero additional effort on your part. In places where this is not appropriate, a simple reference counting scheme may be used, but the idea is to keep the number of rc'd objects small. Do not use cyclical data structures. Enforce a constraint: zero cycles. For data structures like arbitrary graphs, keep an array of vertices and an array of edges that reference vertices by index.
If you use a language with GC, you're probably just contributing to global warming.
- kaba0 4y agoWhy not just write embedded programs with fixed size memory allocation then if we are that okay with restricting the programs we write?
- eru 4y agoDoesn't RAII only work when your lifetimes are in a nested hierarchy? (Basically, your lifetimes have to be the same as your scopes, which are in a simple tree structure only.)