I'm using strings.Split to split a string.
I would like my program to retain one of the elements of the array and release the underlying array.
Unfortunately I can't figure out how to convert a slice of a string into a string that doesn't refer to the underlying string.
Am I supposed to do something like this:
func unslice(s string) (string) {
return string([]byte(s))
}
The background is:
- the underlying string is very large
- the slice I want to retain is very small
- the slice I want to retain will be retained for a long time
- the program will run for a long time - weeks or more
- during the lifetime of the program it will split many of these strings (millions)
Here is an example in response to the comment.
func takesBigStringOften(big string) {
parts := strings.Split(big, " ")
saveTinyStringForALongTime(parts[0])
}