3 ms·
"I mean, for native code, your stack is also just allocated space in memory, right?" Yes. At least on Linux the thread stacks and the memory on the heap are us
by weinzierl 3y ago
"I mean, for native code, your stack is also just allocated space in memory, right?"
Yes. At least on Linux the thread stacks and the memory on the heap are usually allocated with the same syscall (mmap) even. So, the difference is not a question of provenance but how the memory is managed. The native stack is the one the (hardware register) stack pointer points to and there can only be one per thread.
Since this stack's management is hardware supported it can be very fast and efficient. Of course, nothing prevents you from having as many stacks on the heap as you like and manage them yourself. From all I know this is not what managed languages do, but I think they still rely on the amenities of the hardware supported stack.