From the course: Rust Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Stack and heap memory

Stack and heap memory - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Stack and heap memory

- [Instructor] So far, we've looked at how information can be stored using different data types, but we have not talked about where that data is held in memory, how it's organized and how your program accesses it. In some higher level programming languages like Python, you don't need to worry about any of that because those details are all abstracted away from you as the programmer. But Rust is designed for lower levels systems programming, and which part of memory a variable lives in can affect how you use it. In Rust, the program memory that's used to hold working data is divided into two sections called the stack and the heap, which store and access data in different ways. Values in the stack are stored sequentially in the order they receive. Those values are added and removed in a last in, first out or LIFO manner, which means when we remove data from the stack, the value that was added most recently will be the first…

Contents