On Tue, Nov 1, 2022, 20:36 Frank Jüdes <jued...@gmail.com> wrote: > I have to write a program that should verify the content of > configuration-servers. It will need a lot of pre-initialized data to verify > the actual content of a server, so it has to initialize many strings. What > i know from other C-style languages is, that code like > > var MyString *string = 'Hello World!'; > > Will result in having two identical copies of the string »Hello World!« in > the memory: The first one within the program-code itself and a second copy > somewhere in the heap-memory. >
I think the string backing array will be in the text segment as in C. The string header will end in the data segment, provided it's a package scoped variable, but the header has no direct equivalent in C. How will the go-compiler handle something like this: > > package main > import ("fmt") > type MyStruct struct { > Text string > Count int32 > } > func main() { > MyVar := MyStruct{Text: "Hello World!", Count: 20 } > fmt.Printf("%#v\n",MyVar) } > > Will there be two copies of the string »Hello World!" in the memory or > just one? > The backing string array will exist only once, again in the text segment, I believe, because there's no reason for making any copies of it in this case. > Not tested/verified > > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAA40n-XoZNA%2Bfu4G2X%2Bar9pJ4RyrEfYsbY2YmgvGeU%2BeUCwDTQ%40mail.gmail.com.