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 /Variables lives on the stack.md | |
parent | 295b343aecf330e830d79f06e0efc511e7d76da1 (diff) |
Diffstat (limited to 'Variables lives on the stack.md')
-rw-r--r-- | Variables lives on the stack.md | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Variables lives on the stack.md b/Variables lives on the stack.md new file mode 100644 index 0000000..579a984 --- /dev/null +++ b/Variables lives on the stack.md @@ -0,0 +1,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.
\ No newline at end of file |