diff options
author | Jasper Ras <jras@hostnet.nl> | 2025-08-08 22:44:15 +0200 |
---|---|---|
committer | Jasper Ras <jras@hostnet.nl> | 2025-08-08 22:44:15 +0200 |
commit | 22675cd8dc75d8b8d4b0f818f5b093efbc364802 (patch) | |
tree | 90156d37dccf13f012d535e7d92273259e3d5c17 /To put data on the heap use a Box.md | |
parent | 295b343aecf330e830d79f06e0efc511e7d76da1 (diff) |
Diffstat (limited to 'To put data on the heap use a Box.md')
-rw-r--r-- | To put data on the heap use a Box.md | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/To put data on the heap use a Box.md b/To put data on the heap use a Box.md new file mode 100644 index 0000000..442adca --- /dev/null +++ b/To put data on the heap use a Box.md @@ -0,0 +1,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.
\ No newline at end of file |