AboutPostsContact

Stack and Heap Memory

Oleg Korol,•rustnotes
🥞Stack📀Heap

Stack

First in, first out. Faster. Some data-types are entirely stored in Stack Memory, e.g. integers, floating points, booleans, characters, etc.

namevalue
ptrmemory_address
len5
capacity5

ptr: pointer to heap memory
len: length of memory used
capacity: memory allocated

Heap

Slower. Memory has to be allocated and Rust needs to keep track of where to find everything in the heap memory. Some more complex data-types store “metadata” on the Stack Memory and its “content” on the Heap Memory, e.g. String.

indexvalue
0h
1e
2l
3l
4o

Shallow vs Deep Copies

References

CC BY-NC 4.0 2025 © Oleg Korol.RSS