What's the difference, what makes the assignment and direct assignment of the slice, channel and map in GO language

I am a newbie to go to language, have a look at this code section

a := make(map[string]string, 10)
a["name"] = "Blob"
// or
b := map[string]string{}
b["name"] = "Blob"

      

Questions:

"Does" allocate memory on the heap?

     

Does "make" only add one step to the initialization operation? how is the combination of malloc and memset in C language?

+3


source to share


1 answer


The difference is that it make(map[string]string, 10)

provides a capacity hint for the card, but a compound literal map[string]string{}

does not.

Cards are allocated on the heap in both cases.



The function make

allocates and initializes an object just like a compound literal.

+3


source







All Articles