Stack Versus Heap
Get an introduction to stack and heap memory management, which is crucial for understanding how Rust handles memory allocation.
We'll cover the following
Memory management plays a crucial role in the working of the Rust borrow checker. To understand how the borrow checker works, we’ll start at the very basic level—how data is stored on memory level—on two different types of storage: Stack and heap. We’ll first learn how the stack operates.
Stack
One of the areas of memory is known as the stack. It stores information in frames that are more commonly known as stack frames. The stack is a subset of the main memory and occupies a fixed portion of it. Inside the stack’s portion of the main memory, all of our functions and variables are stored. Let’s assume that we are trying to run the following code:
Get hands-on with 1400+ tech skills courses.