Why with the Go {} interface as a parameter, when I call func with a string, will it allocate one alloc / ns?

I have a Go function that has an interface {} as a parameter. When I call a function with a string, it will produce one alloc / ns. Why?

   func foo(...interface{}) error {
       ....
   }

   func use() {
     var str = "use it"
     e := foo(str)
     _ = e
   }
+4
source share
1 answer

Internally, an interface variable is a two-word structure. The first word is a pointer to information about the dynamic type of the variable. The second word will either (a) contain a variable dynamic value if it matches the word, or (b) contain a pointer to memory, holding the dynamic value if it is greater.

, , , . .

+5

Source: https://habr.com/ru/post/1542047/


All Articles