mirror of
https://gitee.com/shikong-sk/golang-study
synced 2025-02-24 07:52:16 +08:00
24 lines
383 B
Go
24 lines
383 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
// 结构体占用一块连续的内存空间
|
|
|
|
type memory struct {
|
|
a int8 // 8bit => 1byte
|
|
b int8
|
|
c int64 // 连续的类型不同时 golang 会进行内存对齐 便于快速寻址
|
|
}
|
|
|
|
func main() {
|
|
m := memory{
|
|
a: 10,
|
|
b: 20,
|
|
c: 30,
|
|
}
|
|
|
|
fmt.Printf("%T\t%p\n", m.a, &m.a)
|
|
fmt.Printf("%T\t%p\n", m.b, &m.b)
|
|
fmt.Printf("%T\t%p\n", m.c, &m.c)
|
|
}
|