要点

  • 填充零值(不会进一步初始化),返回指针

  • 可用来简化定义内部类型(int, string…),因为&int是非法的

    1
    2
    3
    4
    i := new(int)

    var j int
    i = &j

参考

  1. https://golang.org/doc/effective_go.html#allocation_new
  2. http://stackoverflow.com/questions/9320862/go-why-would-i-make-or-new
  3. http://stackoverflow.com/questions/13244947/is-there-a-difference-between-new-and-regular-allocation?lq=1

留言

2015-10-27