Closed
Description
What version of Go are you using (go version
)?
$ go version go version go1.20.7 windows/amd64
Does this issue reproduce with the latest release?
I have checked the issue with go1.20
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go envset GOEXE=.exe set GOEXPERIMENT= set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOINSECURE= set GONOPROXY= set GONOSUMDB= set GOOS=windows set GOPRIVATE= set GOPROXY=https://proxy.golang.org,direct set GOROOT=C:\Program Files\Go set GOSUMDB=sum.golang.org set GOTMPDIR= set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64 set GOVCS= set GOVERSION=go1.20.7 set GCCGO=gccgo set GOAMD64=v1 set AR=ar set CC=gcc set CXX=g++ set CGO_ENABLED=0 set GOMOD=D:\poc\go.mod set GOWORK= set CGO_CFLAGS=-O2 -g set CGO_CPPFLAGS= set CGO_CXXFLAGS=-O2 -g set CGO_FFLAGS=-O2 -g set CGO_LDFLAGS=-O2 -g
What did you do?
I have small snippet where I creates slice of string
Then I copied that slice of string into another variable
Both variable in later flow of code has append call
Ideally the memory address should be different for both of them ,
But the memory address are same for both slice var
Here is an example code
import (
"fmt"
"os"
)
func main() {
mp := map[string]string{
"X": "AB",
"Y": "CD",
}
array1 := getEnv(mp)
array2 := array1
fmt.Printf("memory pointer for array1 %p\n", array1)
fmt.Printf("memory pointer for array2 %p\n", array2)
array2 = append(array2, "proxy1", "proxy2", "proxy3", "proxy4")
array1 = append(array1, "flag1", "flag2", "flag3")
fmt.Println("After update in both array")
fmt.Printf("memory pointer for array1 %p\n", array1)
fmt.Printf("memory pointer for array2 %p\n", array2)
}
func getEnv(mp map[string]string) []string {
x := os.Environ()
for k, v := range mp {
x = append(x, fmt.Sprintf("%s=%s", k, v))
}
return x
}
What did you expect to see?
In later print (after append ) statement memory address should be different
What did you see instead?
Memory address are same even after append call
Output
memory pointer for array1 0xc0000d0000
memory pointer for array2 0xc0000d0000
After update in both array
memory pointer for array1 0xc0000d0000
memory pointer for array2 0xc0000d0000