Re: [go-nuts] Stack based slice usage and unsafe

2019-05-27 Thread Ian Lance Taylor
On Mon, May 27, 2019 at 2:18 AM Sergey Kamardin wrote: > > On Sun, 05/26/19, May 26, 2019 at 07:59:07PM -0400, Ian Lance Taylor wrote: > > This is not valid. The rule is that SliceHeader is only valid when > > inspecting an actual slice header. You have to write > > > > h.Data = uintptr(unsa

Re: [go-nuts] Stack based slice usage and unsafe

2019-05-27 Thread roger peppe
On Mon, 27 May 2019, 07:18 Sergey Kamardin, wrote: > Hello Ian, > > Thank you for your answer. > > On Sun, 05/26/19, May 26, 2019 at 07:59:07PM -0400, Ian Lance Taylor wrote: > > This is not valid. The rule is that SliceHeader is only valid when > > inspecting an actual slice header. You have t

Re: [go-nuts] Stack based slice usage and unsafe

2019-05-26 Thread Sergey Kamardin
Hello Ian, Thank you for your answer. On Sun, 05/26/19, May 26, 2019 at 07:59:07PM -0400, Ian Lance Taylor wrote: > This is not valid. The rule is that SliceHeader is only valid when > inspecting an actual slice header. You have to write > > h.Data = uintptr(unsafe.Pointer(&b)) > h.Len

Re: [go-nuts] Stack based slice usage and unsafe

2019-05-26 Thread Ian Lance Taylor
On Sun, May 26, 2019 at 11:30 AM Sergey Kamardin wrote: > > func ReadHeader(r io.Reader) (Header, error) { > var ( > b [16]byte > bts []byte > ) > h := (*reflect.SliceHeader)(unsafe.Pointer(&b

Re: [go-nuts] Stack based slice usage and unsafe

2019-05-26 Thread Jan Mercl
On Sun, May 26, 2019 at 5:30 PM Sergey Kamardin wrote: I'm not sure what the goal is, but the code looks like doing the same as just `bts := b[:]`. But then it's equal to just `bts := make([]byte, 16)`. Remember, there si no stack nor heap wrt the language specification, so there is no guaranteed