如何计算复杂映射变量的内存大小

时间:2019-09-25 06:59:28

标签: go

我正在尝试计算内存中变量(EntryMap)的大小。

df:
    val,data
    1,(cid:32)(cid:76)(cid:97)(cid:116) man (cid:101) (cid:80)(cid:97)(cid:121)
    2,(cid:32) hi (cid:76)(cid:97)(cid:116)(cid:101) (cid:80)(cid:97)(cid:121),
    3,(cid:32)(cid:76)(cid:97)(cid:116)(cid:101) (cid:80)(cid:97) cat (cid:121)

code (not working):
    if 'cid:' in df.iterrows():
        [tab] text_str = text_str.strip('(')
        [tab] text_str = text_str.strip(')')
        [tab] ascii_num = text_str.split(':')[-1]
        [tab] ascii_num = int(ascii_num)
        [tab] text_val = chr(ascii_num)
        return text_val

到目前为止,我是这样的:

type Entry interface {
    A() string
    B() string
    C() time.Time
    D() int64
}

type Entries []Entry
type EntryMap map[string]Entries

这是确定内存中变量大小的正确方法吗?

1 个答案:

答案 0 :(得分:0)

这不是您可以及时计算的东西...

但是我为您准备了测试场。

https://play.golang.org/p/V_2fheWHQn-


type Entry interface {
    A() string
    B() string
    D() int64
}

type Entries []Entry
type EntryMap map[string]Entries

func main() {

    size := memcalc(func() {
        /* Put your code here */
        var hm = make(EntryMap)

        // do something with map, grow, for example        

        // pass variable to this function to measure
        calc(hm)
    })

    fmt.Println(size)
}