Fearless Security: Memory Safety

Fearless Security: Memory Safety

If we visit that memory address, there will be some data there, so we say that the pointer is a reference to (or points to) that data. On one end, languages like C/C++ are efficient, but require manual memory management; on the other, interpreted languages use automatic memory management (like reference counting or garbage collection [GC]), but pay the price in performance. All Rust code follows certain ownership rules that allow the compiler to manage memory without incurring runtime costs:

Values can be moved or borrowed between variables. Rust prohibits the use of uninitialized variables and dangling pointers, which can cause a program to reference unintended data. If the code in the example below compiled, would reference memory that is deallocated when goes out of scope—a dangling pointer.

Source: hacks.mozilla.org