亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

uint64 是否需要 8 個字節的存儲空間?

uint64 是否需要 8 個字節的存儲空間?

Go
慕的地8271018 2021-06-10 14:08:40
官方文檔說 uint64 是一個 64 位的無符號整數,這是否意味著任何 uint64 數字都應該占用 8 個字節的存儲空間,無論它有多小或多大?編輯:謝謝大家的回答!當我注意到binary.PutUvarint最多消耗 10 個字節來存儲一個 large 時uint64,我提出了疑問,盡管最大uint64應該只需要 8 個字節。然后我在 Golang lib 的源代碼中找到了我的疑問的答案:Design note:// At most 10 bytes are needed for 64-bit values. The encoding could// be more dense: a full 64-bit value needs an extra byte just to hold bit 63.// Instead, the msb of the previous byte could be used to hold bit 63 since we// know there can't be more than 64 bits. This is a trivial improvement and// would reduce the maximum encoding length to 9 bytes. However, it breaks the// invariant that the msb is always the "continuation bit" and thus makes the// format incompatible with a varint encoding for larger numbers (say 128-bit).
查看完整描述

3 回答

?
繁星coding

TA貢獻1797條經驗 獲得超4個贊

簡單地說:是的,64 位固定大小的整數類型總是需要 8 個字節。如果不是這種情況,那將是一種不尋常的語言。

有些語言/平臺支持可變長度數字類型,其中內存中的存儲確實取決于值,但您不會以這種簡單的方式指定類型中的位數,因為這可能會有所不同。


查看完整回答
反對 回復 2021-06-21
?
ITMISS

TA貢獻1871條經驗 獲得超8個贊

Go 編程語言規范

數字類型

數字類型表示整數或浮點值的集合。預先聲明的與體系結構無關的數字類型是:

uint64      the set of all unsigned 64-bit integers (0 to 18446744073709551615)

是的,正好是 64 位或 8 個字節。


查看完整回答
反對 回復 2021-06-21
  • 3 回答
  • 0 關注
  • 738 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號