map memory usage

306 views
Skip to first unread message

pierre...@gmail.com

unread,
Jan 31, 2020, 5:48:33 AM1/31/20
to golang-nuts
Hello,

Is there a better way to estimate the memory usage of a map, other than the following:

Thanks!

Ian Lance Taylor

unread,
Jan 31, 2020, 9:45:23 AM1/31/20
to pierre...@gmail.com, golang-nuts
On Fri, Jan 31, 2020 at 2:48 AM <pierre...@gmail.com> wrote:
>
> Is there a better way to estimate the memory usage of a map, other than the following:
> https://play.golang.org/p/MLSd84CJB3R

The memory usage of a map is going to depend on the history of how the
map is used.

That said, a map is an array of buckets. Each bucket holds 8 keys and
8 values. The buckets will normally be more than half full on
average, though that will depend on the exact history of additions and
deletions. You can use that information to roughly estimate the
memory usage of a map given the key size, the value size, and the
number of entries.

Ian
Reply all
Reply to author
Forward
0 new messages