This is a creation in Article, where the information may have evolved or changed.
This article is to learn <<go language programming >>--Tsinghua University Press (Wang Peng authored) January 2014 first edition of some notes, if there is infringement, please inform the author, will be deleted within 24 hours, reproduced please indicate the source!
The go language has two memory allocation mechanisms, namely the built-in function new () and make ().
-New ()
-Definition: Func new (type) * Type
-The return value is a memory block pointer
-New () is a built-in function that differs from the new operator in other languages, and it only zeros the memory instead of initializing the memory.
-Make ()
-Definition: Func make (type, size Integertype) Type
-When the Make () function is called, the type must be a reference type (Slice, Map, or Channel), Integertype specifies the number of objects to be created.
-Make () The return value is an object, not a memory space pointer returned by new.
-Make vs. new
var p * []intnew([]int)var v []int = make ([]int , 10)