Created
March 16, 2024 12:48
-
-
Save qi7chen/90d829a6dfa7cb0ebe2534ad1b0ab036 to your computer and use it in GitHub Desktop.
print golang type gcdata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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