【发布时间】:2018-12-28 03:21:06
【问题描述】:
我目前正在尝试获取 Go 中复杂结构的大小。
我已经阅读了使用 reflect 和 unsafe 的解决方案,但这些解决方案都不能帮助包含数组或映射(或任何其他指向基础数据结构的指针的字段)的结构。
例子:
type testStruct struct {
A int
B string
C struct{}
items map[string]string
}
如果items 包含一些值,我如何找出上面的正确字节大小?
【问题讨论】:
-
items中值的数量不会改变testStruct值的大小
标签: go reflection go-reflect