jianfeng ye,

Post text not images!

Experiments that are not reproducible have no value. You posted 
low-contrast images of your experiments and results. Reproducing your 
results using OCR and/or typing is too hard and too error prone.

My experiments are: 

$ go version
go version devel +a5032bc86c Thu Apr 11 21:47:52 2019 +0000 linux/amd64

xconst.go:

package main

const l, c int = 1, 3

func main() {
    a := make([]int, l, c)
    a = append(a, 4)
    println(a)
}

Playground: https://play.golang.org/p/lFfUqN49RcO

xvar.go:

package main

var l, c int = 1, 3

func main() {
    a := make([]int, l, c)
    a = append(a, 4)
    println(a)
}

Playground: https://play.golang.org/p/ycRppR_Q1TP

My experiments show that the Go gc compiler is an optimizing compiler. 
Values (const) known at compile time may be used to optimize generated 
code. That is not possible for values (var) only known at runtime.
 
Do your experiments show that your Go compiler is an optimizing compiler?

Peter


On Thursday, April 11, 2019 at 6:19:30 AM UTC-4, jianfeng ye wrote:
>
> Some article tell me when slice use append function, if slice's cap 
> is satisfy,it will not grow slice。
>
> but I want to know when golang know the slice's cap is satisfy?
>
> so, i write a code like this:
>
> [image: 1111111.jpeg]
> and compile it, got
>
>
> [image: 222222.png]
>
>
> then, i write another code:
>
> [image: 3333333.png]
>
> complie:
>
> [image: 44444444.png]
>
>
> i found two code just different in slice's cap,but the compile result is 
> different, one call growslice, one does not.
>
>
> so does it mean the go compiler will check slice's cap to check whether it 
> need use growslice?
>
>
>
>
>
>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to