Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> But as far as I understand golang's memory internals, they still offer you to use the copy-based stack directly ("var some SomeStruct;") or to allocate things directly on the heap (via "new(SomeStruct) / make(SomeStruct)".

Those are equivalent calls, you can't explicitly choose to allocate on the stack/heap.

Conceptually there's no distinction between the stack and heap in Go, you just allocate whatever memory you want and the runtime handles cleanup for you.

In practice the compiler will perform escape analysis to place everything it can on the stack, but that's an implementation detail, you don't get to explicitly choose when allocating.

At best you can get the escape analyzer to show what it thinks escapes to the heap and try to coax it to allocate on the stack instead.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: