Skip to content

Commit bb7381e

Browse files
author
刘建秋
committed
add reflect
1 parent d5feaff commit bb7381e

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

EN/reflect.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,34 @@ const (
3939
4040
```
4141

42+
### Reflected structure TypeOf underlying structure:
43+
```
44+
45+
func TypeOf(i interface{}) Type {
46+
eface := *(*emptyInterface)(unsafe.Pointer(&i)) // runtime.eface
47+
return toType(eface.type)
48+
}
49+
50+
type Type interface {
51+
Align() int
52+
FieldAlign() int
53+
Method(int) Method
54+
MethodByName(string) (Method, bool)
55+
NumMethod() int
56+
Name() string
57+
PkgPath() string
58+
Size() uintptr
59+
String() string
60+
Kind() Kind //Kind Sign
61+
Implements(u Type) bool
62+
AssignableTo(u Type) bool
63+
ConvertibleTo(u Type) bool
64+
Comparable() bool
65+
//... more fields
66+
}
67+
68+
```
69+
4270
### General principles of reflection performance
4371

4472
The general principles of numerical analysis of benchmark results suggest:

zh_CN/reflect.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,34 @@ const (
3939
4040
```
4141

42+
### 反射的结构TypeOf底层结构:
43+
```
44+
45+
func TypeOf(i interface{}) Type {
46+
eface := *(*emptyInterface)(unsafe.Pointer(&i)) // runtime.eface
47+
return toType(eface.type)
48+
}
49+
50+
type Type interface {
51+
Align() int
52+
FieldAlign() int
53+
Method(int) Method
54+
MethodByName(string) (Method, bool)
55+
NumMethod() int
56+
Name() string
57+
PkgPath() string
58+
Size() uintptr
59+
String() string
60+
Kind() Kind //Kind Sign
61+
Implements(u Type) bool
62+
AssignableTo(u Type) bool
63+
ConvertibleTo(u Type) bool
64+
Comparable() bool
65+
//... 更多字段
66+
}
67+
68+
```
69+
4270
### 反射性能的一般原则
4371

4472
基准测试结果的数值分析的一般原则建议:

0 commit comments

Comments
 (0)