I'm trying to marshal an array into a string, separating all elements with newlines. I'm running out of memory and think about a more efficient way to do this.
buffer := "" for _, record := range all_data { body, _ := json.Marshal(record) buffer += string(body) + "\n" // i run out of memory here Question:
Is there a way to append a newline character to a byte array? Right now I'm casting via string(body), but I think that this operation allocates a lot of memory (but maybe I'm wrong).
bufferlater in your app?stringis constant in Golang. It's better to usebytes.Bufferinstead and also other language whichstringis constant.