Hello Bogdan
You're asking a very legit question. Slices are powerful but using combinations 
of append and reslicing can be surprisingly subtle.

Step1 is easy: slicing is basically creating a new header referencing a 
position in an existing array, it does NOT by itself modify src.

Step3 is more difficult: dst and src don't share any overlapping memory 
location anymore, though they did in Step1 and Step2. This is what happens when 
appending elements beyond capacity (beyond last slot of underlying array): then 
a fresh new array is allocated and returned, now independent from src. To 
understand why there is an overflow at all (even if dst has no more than 8 
items), you must consider that after Step1, the fist slot of dst is the seond 
slot of the underlying array.

Hope this helps.
Same sort of puzzle here: https://go-traps.appspot.com/#append

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