Skip to content

Conversation

@Kobzol
Copy link

@Kobzol Kobzol commented Oct 20, 2022

This part is a bit misleading. The address of stack variables is not known at compilation time, stack can be located pretty much anywhere in the address space. Local variables are accessed in the same way as memory on the heap, using their addresses (or rather by something like [RBP + X], but that's not inherently faster than e.g. [EAX]).

Using stack memory can indeed be faster, but for other reasons:

  • Access patterns - due to its nature, stack accesses occur repeatedly within a small area of memory, so it can be effectively cached.
  • Layout - due to its nature, the memory is placed close together, which again helps cached.
  • Allocation - stack allocation/deallocation is super simple and fast.

This part is a bit misleading. The address of stack variables is not known at compilation time, stack can be located pretty much anywhere in the address space. Local variables are accessed in the same way as memory on the heap, using their addresses (or rather by something like `[RBP + X]`, but that's not inherently faster than e.g. `[EAX]`).

Using stack memory can indeed be faster, but for other reasons:
- Access patterns - due to its nature, stack accesses occur repeatedly within a small area of memory, so it can be effectively cached.
- Layout - due to its nature, the memory is placed close together, which again helps cached.
- Allocation - stack allocation/deallocation is super simple and fast.
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

Successfully merging this pull request may close these issues.

1 participant