Allocation with new

Go에서는 기본적으로 두 가지 할당 방법이 존재한다. 바로 new와 make이다.

Constructors and composite literals

때로는 제로 값만으로 충분하지 않고 생성자를 초기화 하는 것이 필요한 경우도 존재함

func NewFile(fd int, name string) *File {
    if fd < 0 {
        return nil
    }
    f := new(File)
    f.fd = fd
    f.name = name
    f.dirinfo = nil
    f.nepipe = 0
    return f
}
func NewFile(fd int, name string) *File {
    if fd < 0 {
        return nil
    }
    f := File{fd, name, nil, 0}
    return &f
}