summaryrefslogtreecommitdiff
path: root/Variables lives on the stack.md
blob: 579a984efa455c0561a85f99b3df1257f87e3030 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[[Rust]]
[[To put data on the heap use a Box]]


---
Each function has a frame consisting of variables. Those frames live on the stack.

A frame is **deallocated when the function returns**.

If we assign a variable such as 
```rust
let a = [0; 1_000_000];
let b = a;
```

the value of a is **copied** to b (thus we get two huge arrays). This is **expensive**. Think about what happens when we call a function.