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) | 
make slice
- Remember that make applies only to maps, slices and channels and does not return a pointer. To obtain an explicit pointer allocate with new or take the address of a variable explicitly.
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
data-constructor.go
return 的另外一种写法
NewFile是一种推崇的constructor写法