On Sat, Oct 22, 2016 at 6:40 PM, T L <tapir....@gmail.com> wrote:
>
> On Saturday, October 22, 2016 at 11:59:55 PM UTC+8, Ian Lance Taylor wrote:
>>
>> On Sat, Oct 22, 2016 at 2:01 AM, T L <tapi...@gmail.com> wrote:
>> >
>> > On Saturday, October 22, 2016 at 4:57:52 PM UTC+8, T L wrote:
>> >>
>> >>
>> >> The string struct used internally is
>> >>
>> >> type stringStruct struct {
>> >>     str unsafe.Pointer
>> >>     len int
>> >> }
>> >>
>> >> When following f function is called and s is cleared,
>> >> how do go runtime knows the starting memory address of the old s.str is
>> >> "a" instead of "c"?
>> >
>> >
>> > I mean how do go runtime knows "abcdefg" instead of "cde" should be
>> > released.
>>
>> The garbage collector works in terms of allocated memory blocks.  If
>> there is a pointer into the memory block, it is retained.  If there
>> are no remaining pointers to the block, it is released.  The fact that
>> the string points into the middle of the block only matters in that it
>> causes the block to be retained.  Where the string points has no
>> effect on what is released when there are no remaining pointers to the
>> block.
>
>
> So a string always occupy most one block, no matter how large the string is?

Yes.

Ian

-- 
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