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

I agree, but if that's the case, then maybe zig's philosophy of simply creating local memory allocators really is the good pattern ?


Yes, it is indeed a good trade-off. That strategy is called a region-based memory management in general, and in fact Rust's borrow checker is its generalization, automatically generating fine-grained small regions that are called "lifetimes" ;-) So they are valid approaches, just that Rust borrow checking is much broader that safe Rust covers wide use cases.


Isn’t it essentially the same pattern except unsafe if you don’t have a borrow checker?

If you have indices into an array you need access to that array, once the array is gone the indexes are “dead”.

If you have pointers into local memory without any sort of borrow checking once the local memory is gone you have UAFs.


Sort of. They do make many patterns far easier to reason about also without help. E.g. in this case, for any memory only used internally by the parser and NFA, guaranteeing that indices or pointers to the underlying memory isn't leaked at all is often fairly easy, and certainly easier than trying to keep precise track of what to free when.

Having it done for you automatically is certainly even better, but if you're first saddled with manual memory management, it's better than nothing.




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

Search: