3 ms·
Well, I don't know about borrow checkers, but scoped memory was added to C++ over a decade ago. In fact, I led the charge to remove every single new and delete
by plasticeagle 4y ago
Well, I don't know about borrow checkers, but scoped memory was added to C++ over a decade ago. In fact, I led the charge to remove every single new and delete from our codebase, and cause add it to the list of things disallowed by the static analysis tools.
Today, I wouldn't use new or delete in any C++ program for any reason. Segfaults and null pointers have become extremely rare.
- John23832 4y agoThanks for the response. I appreciate that RAII is in C++ as well. RAII is an addition to C++. You can write valid C++ with memory leaks all over the place. This is the nature of being a superset of C. In Rust, there is no other way (outside of using unsafe). It is a language based around compile time memory safety. Segfaults and null pointers aren't extremely rare, they're extremely rare in modern C++ (which is a subset of all C++) The borrow checker validates references as they are passed throughout your program. You can have either (many immutable references || one mutable references). This may seem simple but is key to the memory safety ideas. The usages of references are validated. Move semantics are checked at compile time.
- rami3l 4y agoHowever the borrow checker is not only about new/delete, it also prevents other forms of reference invalidations (e.g. when holding a reference to a vector element while appending to the vector, that reference can become invalid when the vector gets resized).