Any difference in using an empty interface or an empty struct as a map’s value?

Memory usage. For example, types struct{}, interface{}, and bool,

package main

import (
    "fmt"
    "unsafe"
)

func main() {
    var s struct{}
    fmt.Println(unsafe.Sizeof(s))
    var i interface{}
    fmt.Println(unsafe.Sizeof(i))
    var b bool
    fmt.Println(unsafe.Sizeof(b))
}

Output (bytes for 32-bit architecture):

0
8
1

Output (bytes for 64-bit architecture):

0
16
1

References:

Go Data Structures: Interfaces

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)