Advertisement

Go如何判断变量是否在栈或堆中?

阅读量:

How do I know whether a variable is allocated on the heap or the stack?

From a semantic perspective, there’s no requirement to be aware of how variables are stored. Variables in Go persist so long as they remain referenced. The choice of storage location by an implementation is inconsequential with respect to the language’s semantics.

The storage mechanism for a program influences the efficiency of its code generation. When feasible, Go compilers allocate variables local to a function within its stack frame. However, if the compiler cannot establish that a variable is not referenced afte

全部评论 (0)

还没有任何评论哟~