Reference to string literals in Go

前端 未结 5 1141
忘了有多久
忘了有多久 2021-01-01 15:27

In my application I will frequently pass references to a static string. I wish to avoid having Go allocate memory for each call, but I failed to get the address to my string

5条回答
  •  抹茶落季
    2021-01-01 16:08

    A string in go is immutable and is just a pointer and a length (total length : 2 words).

    So you don't have to use a pointer to handle it efficiently.

    Just pass the string.

提交回复
热议问题