First, I’m new to Go language.
I came across an example that demonstrates how stack growth works. The code simply passes an int array and an arbitrary string to a recursive function to bloat stack memory.
So when it exceeded its size, the stack will be reallocated, the size is doubled every reallocation. We know the reallocation taking place by looking at that arbitrary string’s address change.
However, if we use standard library print - fmt.print() instead (or both built-in and fmt), the demonstration fails. https://play.golang.org/p/5wqICD9A_AP
The only explanation that I can think of is that the Go decides to allocate that string in the heap during compile-time if we use fmt.print. But what causes that?
I’ve been perplexed for three days, still not yet figure out why.