go - Best practices constructing an empty array in GoLang? -
i'm wondering best practices when initializing empty arrays.
i.e. there difference here between arr1, arr2, , arr3?
myarr1 := []int{} myarr2 := make([]int,0) var myarr3 []int
i know make empty []int
wonder, 1 syntax preferable others? find first readable that's beside point here. 1 key point of contention may array capacity, presumably default capacity same between 3 unspecified. declaring arrays of unspecified capacity "bad"? can assume comes performance cost how "bad" really?
/tldr
- is there difference between 3 ways make empty array?
- what default capacity of array when unspecified?
- what performance cost of using arrays unspecified capacity?
first, it's slice not array. arrays , slices in go different, arrays have fixed size part of type. had trouble @ first :)
- not really. if 3 correct, , difference should small worry about. in own code use whatever easiest in particular case.
- 0
- nothing, until need add item, whatever costs allocate storage needed.
Comments
Post a Comment