Stack and Heap
Stack and Heap
| Stack Segment |
Stack Space Heap Space
High Address -> Low Address
Go’s stack segment has no guard page mechanism. Instead, it inserts checking code during function calls. This trades time for space—a classic design choice. Inlining can reduce the number of these checks.
Early Stack Management
When the stack exceeded its allocated size limit, Go would grab a chunk from the heap. But this had clear downsides. The frequent allocation and deallocation costs were high. This created classic hot splitting problems.
Modern Stack Management
When the stack grows too small, Go allocates a larger stack space and copies the old stack over.