Pointer to a map

后端 未结 3 694
予麋鹿
予麋鹿 2020-12-24 01:47

Having some maps defined as:

var valueToSomeType = map[uint8]someType{...}
var nameToSomeType = map[string]someType{...}

I would want a var

3条回答
  •  执念已碎
    2020-12-24 02:31

    More specifically, from the Golang Specs:

    Slices, maps and channels are reference types that do not require the extra indirection of an allocation with new.
    The built-in function make takes a type T, which must be a slice, map or channel type, optionally followed by a type-specific list of expressions.
    It returns a value of type T (not *T).
    The memory is initialized as described in the section on initial values

    However, regarding function calls, the parameters are passed by value (always).
    Except the value of a map parameter is a pointer.

提交回复
热议问题