I need to make function that calculating hash of multiple large strings concatenation. How to do it efficient in go? To avoid unnecessary memory copies
I updated the question. Now the question is there a difference between make_hash and make_hash_ptr
func make_hash(v ...string) string {
h := sha256.New()
for _, s := range v {
h.Write([]byte(s))
}
return hex.EncodeToString(h.Sum(nil))
}
func make_hash_ptr(v ...*string) string {
h := sha256.New()
for _, s := range v {
h.Write([]byte(*s))
}
return hex.EncodeToString(h.Sum(nil))
}
func main() {
s1 := "very large string...."
s2 := "very large string...."
s3 := "very large string...."
hash := make_hash(s1, s2, s3)
fmt.Println(hash)
}