Re:Simple techniques to optimise Go programs
by nhooyr on Tuesday June 18, 2019 @03:10PM
(#20217115)
Your example doesn't seem right. Doesn't the Get perform an allocation anyway because you access the value of the pointer and store it in a new variable b? It's very likely b will escape to the heap.
[ Parent
| on HN ]
Re:Simple techniques to optimise Go programs
by peterwaller on Tuesday June 18, 2019 @05:36PM
(#20218702)
I agree with nhooyr's analysis. The interface{} will anyway transparently "contain" a pointer-to-the-[]byte, in other words, the []byte value itself will be heap allocated.
(Note for anyone new to this that the "[]byte-value" - we say "the byte slice" - is a distinct thing from the "values stored-in-the-byte-slice", which is a heap allocated backing array)