eface
eface 结构体表示不包含任何方法的 interface{} 类型,包含指向底层数据和类型的两个指针
// go1.13.9 runtime/runtime2.go 197
type eface struct {
_type *_type
data unsafe.Pointer
}
iface
iface 结构体表示包含方法的接口;
// go1.13.9 runtime/runtime2.go 192
type iface struct {
tab *itab
data unsafe.Pointer
}
itab
// go1.13.9 runtime/runtime2.go 730
type itab struct {
inter *interfacetype
_type *_type
link *itab
hash uint32 // copy of _type.hash. Used for type switches.
bad bool // type does not implement interface
inhash bool // has this itab been added to hash?
unused [2]byte
fun [1]uintptr // variable sized
}
interfacetype
// go1.13.9 runtime/type.go 354
type interfacetype struct {
typ _type //类型
pkgpath name // 包路径
mhdr []imethod //接口定义的函数列表
}
_type
type _type struct {
size uintptr // 类型大小
ptrdata uintptr // size of memory prefix holding all pointers
hash uint32 // 类型hash
tflag tflag // 类型flag
align uint8 // 类型对齐
fieldalign uint8
kind uint8 //类型
alg *typeAlg
// gcdata stores the GC type data for the garbage collector.
// If the KindGCProg bit is set in kind, gcdata is a GC program.
// Otherwise it is a ptrmask bitmap. See mbitmap.go for details.
gcdata *byte
str nameOff
ptrToThis typeOff
}
size类型占用的内存空间,为内存空间的分配提供信息;hash
字段能够帮助我们快速确定类型是否相等