This question already has an answer here:
If we use a map like map[string]string
Is it possible to get a actual memory use of map from the code below?
for i, v := range x.(map[string]string) {
CacheBytes += len([]byte(i))
CacheBytes += len([]byte(v))
}
When I trying to get memory bytes from variable, I did like
// get bytes from different types
switch x.(type) {
// string would be simple
case string:
s = x.(string)
CacheBytes += len([]byte(s))
// but in case of map...?
case map[string]string:
for i, v := range x.(map[string]string) {
CacheBytes += len([]byte(i))
CacheBytes += len([]byte(v))
}
// Or array...????
case []string:
How can we get actual bytes memory that uses by map or array in Golang? I know it's bit complicated coz' of data structure, would be appreciated if anyone can help.
Thanks.
</div>