Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibly remove "stack is faster" from stack overflow section #85

Open
pedropark99 opened this issue Oct 22, 2024 · 0 comments
Open

Possibly remove "stack is faster" from stack overflow section #85

pedropark99 opened this issue Oct 22, 2024 · 0 comments

Comments

@pedropark99
Copy link
Owner

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:

Allocating memory on the stack is generally faster than allocating it on the heap.

By @tauoverpi :

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant