第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

內(nèi)存對齊問題

內(nèi)存對齊問題

侃侃無極 2018-10-24 13:37:58
type W struct {     b byte     i int32     j int64}type W2 struct {     name string     age  int32}var w Wvar w2 W2 fmt.Println(unsafe.Sizeof(w), unsafe.Sizeof(w2))對于w變量我知道內(nèi)存占用應(yīng)該是16,但是w2為啥是24呢?求賜教
查看完整描述

1 回答

?
汪汪一只貓

TA貢獻(xiàn)1898條經(jīng)驗(yàn) 獲得超8個贊

import "fmt"import "unsafe"func main() {    var bs []byte
    fmt.Println("[]byte:", unsafe.Sizeof(bs))    var str string
    fmt.Println("string:", unsafe.Sizeof(str))    var i64 int64
    fmt.Println("int64:", unsafe.Sizeof(i64))    var i32 int64
    fmt.Println("int32:", unsafe.Sizeof(i32))    var stru struct{}
    fmt.Println("struct:", unsafe.Sizeof(stru))       
}

文檔上這么寫的

Sizeof takes an expression x of any type and returns the size in bytes of a hypothetical variable v as if v was declared via var v = x. The size does not include any memory possibly referenced by x. For instance, if x is a slice, Sizeof returns the size of the slice descriptor, not the size of the memory referenced by the slice.


查看完整回答
反對 回復(fù) 2018-10-24
  • 1 回答
  • 0 關(guān)注
  • 775 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號