Stack vs Heap: Memory Allocation Guidelines
Rule of thumb
If the size is known at compile time and lifetime is bound to the function’s execution → keep it on the stack.
If size is unknown until runtime or needs to survive after the function returns → allocate on the heap.
Comments
No comments yet. Be the first!