justin = { main feed , music , code , askjf , pubkey };
Ask Justin Frankel
No reasonable question unanswered since 2009!

Suggested topics: programming, music, sleep, coffee, etc.

Note: please do not ask questions about REAPER features, bugs or scheduling, use the forums instead.


Name: Ask: Human (enter yes):
[back to index] | [unreplied] | [replied] | [recent comments] | [all]

Question: What's the difference between stack and heap allocation, and why is the stack so much faster?
Asked by John (24.234.128.x) on May 20 2010, 1:19pm
Reply on May 22 2010, 9:02am (edited at May 22 2010, 9:03am):
    Well I could link to the appropriate Wikipedia articles on their basic structure, but instead I'll highlight the practical differences from the top of my head:
    1. The stack is much more limited in size, and is thread-local (meaning it is faster because it generally does not need to synchronize any threads to access). On Windows it's typically reserved at just a couple of megabytes, even.
    2. Memory allocated on the stack is temporary, but because of this, it's highly predictable where the memory will be allocated from (which means it is faster to calculate), and also often more likely to be in cache.
    3. The heap is much larger, persistent, and can have allocations managed across threads. This requires thread safety, and more data structures to search for free space when allocating.

Comment:
    Your Name:   -- Site Owner's Name:  (for human-verification)

    Comment:    

    
  
[back to index] | [unreplied] | [replied] | [recent comments] | [all]
Copyright 2025 Justin Frankel. | RSS