1-数据类型内存结构-整数
2019-06-02 本文已影响0人
浩玥当空
1. 整数
type myint32 int32
type myint322 int32
var var_byte byte = 0x12;
var var_rune rune = 0x12;
var var_int8 int8 = 0x12;
var var_int32 int32 = 0x12;
var var_myint32 myint32 = 0x12;
var var_myint322 myint322 = 0x12;
var var_int64 int64 = 0x123456;
var var_float32 float32 = 3.1415926;
var var_float64 float64 = 3.1415926;
var var_uint8 uint8 = 0x12
var var_uint32 uint32 = 0x123456
由汇编可以看出,整数都是根据其字节长度直接存储值的。
不同的是经过type 做了别名定义的整数,会有别名的类型定义信息。如
var_myint32。
"".var_byte SNOPTRDATA size=1
0x0000 12 .
"".var_rune SNOPTRDATA size=4
0x0000 12 00 00 00 ....
"".var_int8 SNOPTRDATA size=1
0x0000 12 .
"".var_int32 SNOPTRDATA size=4
0x0000 12 00 00 00 ....
"".var_myint32 SNOPTRDATA size=4
0x0000 12 00 00 00 ....
"".var_myint322 SNOPTRDATA size=4
0x0000 12 00 00 00 ....
"".var_int64 SNOPTRDATA size=8
0x0000 56 34 12 00 00 00 00 00 V4......
"".var_float32 SNOPTRDATA size=4
0x0000 da 0f 49 40 ..I@
"".var_float64 SNOPTRDATA size=8
0x0000 4a d8 12 4d fb 21 09 40 J..M.!.@
"".var_uint8 SNOPTRDATA size=1
0x0000 12 .
"".var_uint32 SNOPTRDATA size=4
0x0000 56 34 12 00 V4..
type myint32 int32对应的类型信息,定义了两个 type.*"".myint32
,type."".myint32
type..namedata.*main.myint32- SRODATA dupok size=16
0x0000 00 00 0d 2a 6d 61 69 6e 2e 6d 79 69 6e 74 33 32 ...*main.myint32
type.*"".myint32 SRODATA size=56
0x0000 08 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 ................
0x0010 41 ae 9f ea 00 08 08 36 00 00 00 00 00 00 00 00 A......6........
0x0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x0030 00 00 00 00 00 00 00 00 ........
rel 24+8 t=1 runtime.algarray+80
rel 32+8 t=1 runtime.gcbits.01+0
rel 40+4 t=5 type..namedata.*main.myint32-+0
rel 48+8 t=1 type."".myint32+0
runtime.gcbits. SRODATA dupok size=0
type."".myint32 SRODATA size=64
0x0000 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x0010 8a b5 1e d0 07 04 04 85 00 00 00 00 00 00 00 00 ................
0x0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x0030 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 ................
rel 24+8 t=1 runtime.algarray+64
rel 32+8 t=1 runtime.gcbits.+0
rel 40+4 t=5 type..namedata.*main.myint32-+0
rel 44+4 t=5 type.*"".myint32+0
rel 48+4 t=5 type..importpath."".+0
2. 复数
var var_complex64 complex64 = 5 + 10i
var var_complex128 complex128 = complex(5,10)
complex64由8个字节组成。
complex128由16个字节组成。
"".var_complex64 SNOPTRDATA size=8
0x0000 00 00 a0 40 00 00 20 41 ...@.. A
"".var_complex128 SNOPTRDATA size=16
0x0000 00 00 00 00 00 00 14 40 00 00 00 00 00 00 24 40 .......@......$@