Last active
November 3, 2015 03:51
-
-
Save zycbobby/2297b532e867bb2b6ddc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func NewFile(fd int, name string) *File { | |
| if fd < 0 { | |
| return nil | |
| } | |
| f := File{fd, name, nil, 0} | |
| return &f | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # The reason for the distinction is that these three types represent, under the covers, references to data structures that must be initialized before use. | |
| var p *[]int = new([]int) // allocates slice structure; *p == nil; rarely useful | |
| var v []int = make([]int, 100) // the slice v now refers to a new array of 100 ints | |
| // Unnecessarily complex: | |
| var p *[]int = new([]int) | |
| *p = make([]int, 100, 100) | |
| // Idiomatic: | |
| v := make([]int, 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
make slice