On Fri, Jan 29, 2021 at 9:10 AM xie cui <cuiwei...@gmail.com> wrote:
>
> when i call make new explictly, does it mean the space must be in heap, in my 
> mind, it still has chance to alloc in stack in some situation?
> my question is is it must be in heap, or in some case it can alloc in stack?

The builtin function new can return the address of a stack value in some cases.

Writing
    p := new(T)
is approximately the same as writing
    var unnamedVariable T
    p := &unnamedVariable

Whether the new variable is created on the stack or the heap depends
on the compiler's escape analysis of p.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUBK9pJQBknGk%3De8KoTC%3Dx2nbJijrtpEidxeioOw7ZqAw%40mail.gmail.com.

Reply via email to