0
Heap access vs stack access
Hi I have idea that heap memory allocation is slower as it goes to kernal level call and hence making it slower than stack allocation. Once allocation is done, is it still slow to access heap allocated memory compared to stack allocated variable ? If yes , why ?
1 Resposta
+ 1
After allocation, access to memory would operate at the same speed, regardless of heap or stack.
https://stackoverflow.com/questions/24057331/is-accessing-data-in-the-heap-faster-than-from-the-stack
"The stack is faster because the access pattern makes it trivial to allocate and deallocate memory from it (a pointer/integer is simply incremented or decremented), while the heap has much more complex bookkeeping involved in an allocation or free."
Note: I arrived at this answer by typing into Google: "heap stack speed" and taking the first suggested hit.
If you follow the link to stackoverflow, there are much longer and more technical explanations too.