chapter two
2 Memory, variables, and ownership
This chapter covers
- The stack, the heap, pointers, and references
- Strings - The most common way to work with text
- Const and static - Variables that last forever
- Shadowing - When you give a variable the same name as another
- Copy types
- More about printing
In this chapter too you’ll see how Rust keeps you thinking about the computer system itself. Rust keeps you focused on how the computer's memory is being used for your program, and what ownership is (who owns the data). Remember the word “ownership” - it’s probably Rust’s most unique idea. We'll start with the two types of memory that a computer uses: the stack and the heap.
Oh, and there's quite a bit more to learn about printing to build on what you learned last chapter. Look for that at the end!
The stack, the heap, and pointers, are very important in Rust.
The stack and the heap are two places to keep memory in computers. The important differences are: