Hacker News new | past | comments | ask | show | jobs | submit login

Use memory arenas and never think about any of this again.



Sadly, untrue. Source: I use memory arenas, and it's still pretty trivial to copy (instead of reference) an object onto a stack and then try to save a pointer to that object. All you need is to leave out one `&` and the compiler won't tell you anything went wrong: it'll cheerfully let you retain a pointer to a stack-based object that is going to die because explicit lifetime analysis isn't a part of the language spec.


How do arenas prevent out-of-bound access, double free or stale pointers?


Out of bound access is avoided because you ise handles that the arena has given you, creating an invalid handle is restricted. You avoid double free because of Rust's owbership semantics that make the arena itself reaponsible for "deallocation" (which is just blanking the value and letting Drop do its thing). You avoid stale pointers because every access is checked at runtime if you're using a generational arena.


We are talking about C++ ;-)


You're right, I was reading a sister thread that was talking about Rust and lost the plot.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: