the heap is random access :) the stack is LIFO :) i enjoy lying :)
Conversation
Replying to
Technically, they are correct. You have the stack pointer, you can put data there and increase the pointer. Thatβs it. On heap, the OSβs memory management has to search for the right page, find an empty one, etc., etc.
1
Stacks still use the same virtual memory system as the rest of the address space. When you go deeper on the stack than you have before it still triggers acquiring pages the same way as touching newly allocated memory from a userspace allocator. Both end up coming from mmap, etc.
A secondary thread call stack and memory obtained by a userspace allocator are typically obtained from the OS the same way. You can use memory from a userspace allocator as a call stack or memory on the stack as the backing for a userspace allocator. It's about how it's used.
1
Rust notably used to dynamically allocate stacks in chunks from a userspace allocator instead of as a mapping with a guard page and stack probes to detect all the space being exhausted. It could still get an out-of-memory error and exhaust the stack but it wasn't fixed size.


