You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Stack is not always faster than the heap. And explaining the details on how and why the stack is not always faster might not be worth it. Specially because it involves explaining the memory layout in the CPU caches.
Therefore, it might be better to simply remove "stack is faster" from the text:
This is only true if the objects allocated are small enough to fit within cache-lines as allocating larger objects will cause memory fetches similar to infrequent heap access. Thus "generally" should link (or text should follow inline) that it's the access pattern which makes stack memory fast and that if you allocate a region of memory anywhere else and access it as frequently you'll then have the same performance. I've seen this mistake a few times where one allocates MiB of stack space because "stack is fast" which defeats the point every time such a function is called as it's almost always a cache miss.
The text was updated successfully, but these errors were encountered:
Stack is not always faster than the heap. And explaining the details on how and why the stack is not always faster might not be worth it. Specially because it involves explaining the memory layout in the CPU caches.
Therefore, it might be better to simply remove "stack is faster" from the text:
zig-book/Chapters/01-memory.qmd
Line 392 in 491ad4a
By @tauoverpi :
The text was updated successfully, but these errors were encountered: