Hmm, interesting. However, wouldn't that mean that if I removed the 
function and did the following: https://play.golang.org/p/enI6UmYoFJ the 
escape analysis wouldn't happen?

On Wednesday, August 9, 2017 at 1:23:15 PM UTC+12, Marvin Renich wrote:
>
> * sno <farleys...@gmail.com <javascript:>> [170808 20:57]: 
> > package main 
> > 
> > import ( 
> > "fmt" 
> > "reflect" 
> > "unsafe" 
> > ) 
> > 
> > func main() { 
> > a := []byte("1234567") 
> > printSliceDetails(a) 
> > } 
> > 
> > func printSliceDetails(a []byte) { 
> > sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&a)) 
> > fmt.Printf("Backing array location: %v, data: %s, len: %d, cap: %d\n", 
> > sliceHeader.Data, string(a), len(a), cap(a)) 
> > 
> > // fmt.Printf("Backing array location: %v, data: %s, len: %d, cap: 
> %d\n", 
> > // sliceHeader, string(a), len(a), cap(a)) 
> > } 
> > 
> > In the above code, the capacity prints 32. However, if you comment the 
> > first print statement and remove the commenting on the second and run 
> the 
> > program again the capacity will only be 8. What is happening with 
> > sliceHeader.Data to make its capacity grow like that? 
>
> I'm not an expert, but my guess is that the compiler is doing escape 
> analysis and allocating a on the heap in the first case and on the stack 
> in the second case (with different minimum allocation sizes). 
>
> Hopefully someone else can give a more authoritative answer. 
>
> ...Marvin 
>
>

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