On Tue, Sep 4, 2018 at 10:29 AM Ingo Jaeckel <ingo.jaec...@gmail.com> wrote:
> It seems the length of a slice is not considered by unsafe.SizeOf <https://golang.org/pkg/unsafe/#Sizeof>. Rightfully so. The size of a slice is a compile-time constant. > I assume this is a side effect of .SizeOf being evaluated at compile time? Yes, but let's make clear that unsafe.SizeOf(slice) and len(slice) are independent, unrelated values. > What are other idiomatic ways to determine the runtime memory use of a struct which contains (among other things) slices? Use unsafe.SizeOf as you do, it works correctly. The items of a slice are not part of the slice variable/field but are allocated independently elsewhere. The items are found at &slice[0] when len(slice) -- -j -- 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 golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.