O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

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

Function variables and the stack

Rust's memory management hangs on to two concepts: the stack and the heap. Stacks are used for local variables: all the let bindings in your functions are stored in the stack, either as the values themselves or as references to other things. It is an extremely fast and reliable memory allocation scheme. It is fast because allocating and deallocating memory via a stack requires just one CPU instruction: moving the stack frame pointer. It is reliable because of its simplicity: when a function is finished, all its stack memory is released by restoring the stack frame pointer to where it was before entering the function. This makes the stack less versatile, however: there's no way for a thing in the stack to outlive ...

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