Reader small image

You're reading from  Mastering Rust. - Second Edition

Product typeBook
Published inJan 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781789346572
Edition2nd Edition
Languages
Right arrow
Author (1)
Rahul Sharma
Rahul Sharma
author image
Rahul Sharma

Rahul Sharma is passionately curious about teaching programming. He has been writing software for the last two years. He got started with Rust with his work on Servo, a browser engine by Mozilla Research as part of his GSoC project. At present, he works at AtherEnergy, where he is building resilient cloud infrastructure for smart scooters. His interests include systems programming, distributed systems, compilers and type theory. He is also an occasional contributor to the Rust language and does mentoring of interns on the Servo project by Mozilla.
Read more about Rahul Sharma

Right arrow

Approaches to memory allocation

At runtime, memory allocations in a process happens either on the stack or on the heap. They are storage locations that are used to store values during the execution of the program. In this section, we'll take a look at both of these allocation approaches.

The stack is used for short-lived values whose sizes are known as compile time, and is the ideal storage location for function calls and their associated context, which needs to go away once the function returns. The heap is for anything that needs to live beyond function calls. As mentioned in Chapter 1, Getting Your Feet Wet, Rust prefers stack allocation by default. Any value or instance of a type that you create and bind to a variable gets stored on the stack by default. Storing on the heap is explicit and is done by using smart pointer types, which are explained later in this chapter...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Mastering Rust. - Second Edition
Published in: Jan 2019Publisher: PacktISBN-13: 9781789346572

Author (1)

author image
Rahul Sharma

Rahul Sharma is passionately curious about teaching programming. He has been writing software for the last two years. He got started with Rust with his work on Servo, a browser engine by Mozilla Research as part of his GSoC project. At present, he works at AtherEnergy, where he is building resilient cloud infrastructure for smart scooters. His interests include systems programming, distributed systems, compilers and type theory. He is also an occasional contributor to the Rust language and does mentoring of interns on the Servo project by Mozilla.
Read more about Rahul Sharma