# command-line-arguments ./alloc.go:9:13: a escapes to heap ./alloc.go:8:10: new(int) escapes to heap ./alloc.go:9:13: main ... argument does not escape ./alloc.go:11:10: main new(int) does not escape func main() { a := new(int) // ヒープに取れる fmt.Println(a) b := new(int) // スタックに取れる *b = 0xdeadbeef }
YouTube] (https://www.youtube.com/watch?v=0-vWT-t0UHg) Goのメモリ管理(特にスタックのはなし) [Five things that make Go fast | Dave Cheney] (https://dave.cheney.net/2014/06/07/five-things-that-make-go-fast) [Why is a Goroutine’s stack infinite ? | Dave Cheney] (https://dave.cheney.net/2013/06/02/why-is-a-goroutines-stack-infinite) [Contiguous stacks] (https://docs.google.com/document/d/1wAaf1rYoM4S4gtnPh0zOlGzWtrZFQ5suE8qr2sD8uWQ/pub) main.mainより前には何が起きるか [Golang Internals, Part 6: Bootstrapping and Memory Allocator Initialization | Altoros] (https://blog.altoros.com/golang-internals-part-6-bootstrapping-and-memory-allocator-initialization.html)