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

---

The heap is where data can live indefinitely and we can create pointers to it on the stack using a Box.

```rust
let a = Box::new([0; 1_000_000]);
let b = a;
```

Creates an array with 1 million entries on the heap and two variables on the stack that are a *pointer* to that heap data.