One of the main advantages of using Rust over the likes of C is its memory management. For example, C programs will run into buffer overruns and associated undefined behavior if you attempt to write past the end of an array or past an area reserved using malloc
. Rust protects against most of these problems without compromising on efficiency.
In this chapter, we will delve into how Rust handles memory and will cover the following topics:
- Understanding the memory system used within Rust
- How it can go wrong if you're not careful
- Looking at pointers, references, stack overflows, and preventing crashes
- Allocating and freeing up memory