Memory overhead of maps in Go

前端 未结 5 1962
谎友^
谎友^ 2020-12-31 18:42

map[byte]byte{0:10} should be using least 2 bytes, one for value and one per key. But as each hashmap implmentation, there is also a hidden cost per item. What is the memory

5条回答
  •  無奈伤痛
    2020-12-31 19:33

    /*  Hal3 Mon Jul 18 20:58:16 BST 2016 go version go1.5.1 linux/amd64
    Bytes used for 1000 empty maps: 0, bytes/map 0.0
    Bytes used for 1000 maps with 1 entries: 112192, bytes/map 112.2
    Bytes per entry 112.2
    Bytes used for 1000 maps with 2 entries: 113472, bytes/map 113.5
    Bytes per entry 56.7
    Bytes used for 1000 maps with 4 entries: 110912, bytes/map 110.9
    Bytes per entry 27.7
    Bytes used for 1000 maps with 8 entries: 112192, bytes/map 112.2
    Bytes per entry 14.0
    Bytes used for 1000 maps with 16 entries: 231600, bytes/map 231.6
    Bytes per entry 14.5
    Bytes used for 1000 maps with 32 entries: 413768, bytes/map 413.8
    Bytes per entry 12.9
    Bytes used for 1000 maps with 64 entries: 736920, bytes/map 736.9
    Bytes per entry 11.5
    Bytes used for 1000 maps with 128 entries: 1419624, bytes/map 1419.6
    Bytes per entry 11.1
    Bytes used for 1000 maps with 256 entries: 2735192, bytes/map 2735.2
    Bytes per entry 10.7
    Bytes used for 1000 maps with 512 entries: 5655168, bytes/map 5655.2
    Bytes per entry 11.0
    Bytes used for 1000 maps with 1024 entries: 10919888, bytes/map 10919.9
    Bytes per entry 10.7
    Bytes used for 1000 maps with 2048 entries: 21224528, bytes/map 21224.5
    Bytes per entry 10.4
    Bytes used for 1000 maps with 4096 entries: 42391024, bytes/map 42391.0
    Bytes per entry 10.3
    Bytes used for 1000 maps with 8192 entries: 84613344, bytes/map 84613.3
    Bytes per entry 10.3
    Bytes used for 1000 maps with 16384 entries: 169152560, bytes/map 169152.6
    Bytes per entry 10.3
    Mon Jul 18 20:58:25 BST 2016 */
    

提交回复
热议问题