Skip to content

Instantly share code, notes, and snippets.

@qi7chen
Created March 16, 2024 12:48
Show Gist options
  • Save qi7chen/90d829a6dfa7cb0ebe2534ad1b0ab036 to your computer and use it in GitHub Desktop.
Save qi7chen/90d829a6dfa7cb0ebe2534ad1b0ab036 to your computer and use it in GitHub Desktop.
print golang type gcdata
func TestAABB(t *testing.T) {
t.Logf("size of map = %d", unsafe.Sizeof(map[int]int{}))
var a any = gsdb.DbUser{}
var typ = reflectutil.TypeOf(a)
var n = (int(typ.PtrBytes)/8 + 7) / 8
var sb strings.Builder
var ones = 0
for i := 0; i < n; i++ {
var ptr = unsafe.Add(unsafe.Pointer(typ.GCData), i)
var v = *(*uint8)(ptr)
ones += bits.OnesCount8(v)
fmt.Fprintf(&sb, "%08b", bits.Reverse8(v))
}
t.Logf("%s %d GCData: %s", reflect.TypeOf(a).String(), ones, sb.String())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment