O'Reilly logo

Rust Essentials by Ivo Balbaert

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The stack and the heap

Since memory allocation is very important in Rust, we must have a good picture of what is going on. A program's memory is divided into the stack and heap memory parts; to get more background on these concepts, read the information on the classic web page at https://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap. Primitive values such as numbers (like 32 in the figure), characters, and true/false values are stored on the stack, while the value of more complex objects that could grow in size are stored in the heap memory. Heap values are referenced by a variable on the stack, which contains the memory address of the object on the heap:

While the stack has a limited size, the size of the heap can grow ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required