Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



Why not just write embedded programs with fixed size memory allocation then if we are that okay with restricting the programs we write?


Because maybe we're not okay with restricting the programs we write that much.


Nor am I okay with restricting my programs as much as a tree-like only allocation strategy would suffice and circular data structures are not evil.


Doesn'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.)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: