On Tuesday, 4 September 2018 10:29:45 UTC+2, Ingo Jaeckel wrote:
>
> What are other idiomatic ways to determine the runtime memory use of a
> struct which contains (among other things) slices?
>
That depends a lot on your definition of "runtime memory use":
Consider:
a := [100]int16
b := bar{C: a[:]}
Variable a clearly "uses" 200 bytes (maybe plus some for alignment).
But b.C uses a's memory as the backing array. Attributing a slice's
memory to the slice might result in double counting these 200 bytes.
(Same for structs which contain pointers: Two variables may point to
the same object. Where do you count the memory used?).
Maybe it is best to think of bar's memory usage as 4*8 bytes and not
to attribute C's backing array memory to bar.
V.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.