On Friday, March 3, 2017 at 10:32:25 PM UTC+8, Ian Lance Taylor wrote:
>
> On Fri, Mar 3, 2017 at 5:31 AM, T L <tapi...@gmail.com <javascript:>> 
> wrote: 
> > 
> > On Friday, March 3, 2017 at 7:52:42 PM UTC+8, Ian Davis wrote: 
> >> 
> >> Perhaps you can help the discussion by explaining the advantages you 
> see 
> >> in that change? 
> > 
> > 
> > The advantage is to save a few bytes memory and make faster copying. 
>
> I don't see how the suggestion saves memory.  Currently, we can 
> represent a string or slice with a single allocation.  Your suggestion 
> would require us to use two allocations: one for the bytes, and one 
> for the structure pointing to the bytes.  In some cases escape 
> analysis would eliminate that second allocation, but not in all. 
>
> Ian 
>
>
Yes, the suggestion needs more allocations in creating new string and slice 
values.
But it makes copying string and slice values a little faster and a little 
less memory consuming.

 

>
> >> On Fri, 3 Mar 2017, at 11:44 AM, T L wrote: 
> >> 
> >> 
> >> 
> >> On Friday, March 3, 2017 at 4:27:02 PM UTC+8, Konstantin Khomoutov 
> wrote: 
> >> 
> >> On Thu, 2 Mar 2017 23:49:52 -0800 (PST) 
> >> T L <tapi...@gmail.com> wrote: 
> >> 
> >> > After all, the len and cap fields of any value of string and slice 
> >> > values are immutable. 
> >> 
> >> Could you elaborate? 
> >> 
> >> Are you suggesting to replace 
> >> 
> >>   var s []string 
> >> 
> >>   if len(s) ... 
> >>   if cap(s) ... 
> >> 
> >> with 
> >> 
> >>   if s.len ... 
> >>   if s.cap ... 
> >> 
> >> ? 
> >> 
> >> If yes, then what would be the prospective benefits? 
> >> 
> >> 
> >> 
> >> No, I mean why not define string and slice as 
> >> 
> >> type string struct { 
> >>     underlyingString *struct { 
> >>         data *byte 
> >>         len  int 
> >>     } 
> >> } 
> >> 
> >> type slice struct { 
> >>     underlyingSlice *struct { 
> >>         underlyingElements unsafe.Pointer 
> >>         len                int 
> >>         cap                int 
> >>     } 
> >> } 
> >> instead of the current: 
> >> 
> >> type string struct { 
> >>     data *byte 
> >>     len  int 
> >> } 
> >> 
> >> type slice struct { 
> >>     underlyingElements unsafe.Pointer 
> >>     len                int 
> >>     cap                int 
> >> } 
> >> 
> >> 
> >> 
> >> 
> >> 
> >> -- 
> >> You received this message because you are subscribed to the Google 
> Groups 
> >> "golang-nuts" group. 
> >> To unsubscribe from this group and stop receiving emails from it, send 
> an 
> >> email to golang-nuts...@googlegroups.com. 
> >> For more options, visit https://groups.google.com/d/optout. 
> >> 
> >> 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "golang-nuts" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to golang-nuts...@googlegroups.com <javascript:>. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to