Re: [go-nuts] []struct{} vs. []*struct{}

2017-01-11 Thread Ian Davis
On Wed, 11 Jan 2017, at 12:15 AM, Steve Roth wrote: > Suppose you are reading a list of structures, and you do not know in > advance how many there will be. I'm trying to figure out when it's > better to append them to a slice of structures, and when it's better > to append pointers to them to

Re: [go-nuts] []struct{} vs. []*struct{}

2017-01-11 Thread Paul Jolly
This blog post by Russ Cox should help to explain the difference between a struct vs a pointer to a struct, and also the implementation of slices: https://research.swtch.com/godata There is not a single answer to the question on when to use a struct or a pointer to a struct, and not all answers h

Re: [go-nuts] []struct{} vs. []*struct{}

2017-01-11 Thread 'chris dollin' via golang-nuts
On 11 January 2017 at 09:21, Henry wrote: > My understanding is that a slice is an array of pointers. No. A []T (slice of Ts) contains the length and capacity of the slice and a pointer to the backing array of the slice. The backing array is an array of elements of type T (not /pointer/ to T).

[go-nuts] []struct{} vs. []*struct{}

2017-01-11 Thread Henry
My understanding is that a slice is an array of pointers. So your []struct{} is essentially an array of pointers to the structs. Your []*struct{} is an array of pointers to pointers to the structs. In terms of memory allocation, both should be similar. For every modification, a new array is crea

[go-nuts] []struct{} vs. []*struct{}

2017-01-10 Thread Steve Roth
Suppose you are reading a list of structures, and you do not know in advance how many there will be. I'm trying to figure out when it's better to append them to a slice of structures, and when it's better to append pointers to them to a slice of pointers. It's easy enough to to the math on ho