Re: [go-nuts] confused about string allocation

2016-07-11 Thread Ian Lance Taylor
On Mon, Jul 11, 2016 at 4:40 PM, Erich Rickheit KSC wrote: > Ian Lance Taylor wrote: >> On Sat, Jul 9, 2016 at 4:38 PM, Erich Rickheit KSC >> wrote: >> > I found myself writing code like this: >> > >> > s := make([]byte, len) >> > for i := 0; i < len; i++ { >> > /

Re: [go-nuts] confused about string allocation

2016-07-11 Thread Matt Harden
On Mon, Jul 11, 2016 at 5:41 PM Erich Rickheit KSC wrote: > Ian Lance Taylor wrote: > > On Sat, Jul 9, 2016 at 4:38 PM, Erich Rickheit KSC > wrote: > > > I found myself writing code like this: > > > > > > s := make([]byte, len) > > > for i := 0; i < len; i++ { > > >

Re: [go-nuts] confused about string allocation

2016-07-11 Thread Erich Rickheit KSC
Ian Lance Taylor wrote: > On Sat, Jul 9, 2016 at 4:38 PM, Erich Rickheit KSC > wrote: > > I found myself writing code like this: > > > > s := make([]byte, len) > > for i := 0; i < len; i++ { > > // fill in s with stringy goodness > > } > > return st

Re: [go-nuts] confused about string allocation

2016-07-11 Thread Richard Todd
There are places throughout the standard packages where extra copies happen due to []byte <-> string conversion (like strings.Join(), os.*File.WriteString() etc.) I am assuming they don't use an unsafe-magic way to make aliasing strings and []bytes because they don't want people to shoot them

Re: [go-nuts] confused about string allocation

2016-07-11 Thread Manlio Perillo
On Mon, Jul 11, 2016 at 3:28 PM, Ian Lance Taylor wrote: > On Mon, Jul 11, 2016 at 3:49 AM, Manlio Perillo > wrote: >> Il giorno domenica 10 luglio 2016 04:51:21 UTC+2, Ian Lance Taylor ha >> scritto: >>> >>> On Sat, Jul 9, 2016 at 4:38 PM, Erich Rickheit KSC >>> wrote: >>> > I found myself writ

Re: [go-nuts] confused about string allocation

2016-07-11 Thread Ian Lance Taylor
On Mon, Jul 11, 2016 at 3:49 AM, Manlio Perillo wrote: > Il giorno domenica 10 luglio 2016 04:51:21 UTC+2, Ian Lance Taylor ha > scritto: >> >> On Sat, Jul 9, 2016 at 4:38 PM, Erich Rickheit KSC >> wrote: >> > I found myself writing code like this: >> > >> > s := make([]byte, len) >> >

Re: [go-nuts] confused about string allocation

2016-07-11 Thread Manlio Perillo
Il giorno domenica 10 luglio 2016 04:51:21 UTC+2, Ian Lance Taylor ha scritto: > > On Sat, Jul 9, 2016 at 4:38 PM, Erich Rickheit KSC > wrote: > > I found myself writing code like this: > > > > s := make([]byte, len) > > for i := 0; i < len; i++ { > > // fill

Re: [go-nuts] confused about string allocation

2016-07-09 Thread Ian Lance Taylor
On Sat, Jul 9, 2016 at 4:38 PM, Erich Rickheit KSC wrote: > I found myself writing code like this: > > s := make([]byte, len) > for i := 0; i < len; i++ { > // fill in s with stringy goodness > } > return string(s) > > Does this reuse the memory in s

[go-nuts] confused about string allocation

2016-07-09 Thread Erich Rickheit KSC
I found myself writing code like this: s := make([]byte, len) for i := 0; i < len; i++ { // fill in s with stringy goodness } return string(s) Does this reuse the memory in s for the string, or does it allocate new memory and copy? Or does escape an