gpt4 book ai didi

ruby - Ruby 中 bool 值的大小是多少?

转载 作者:太空宇宙 更新时间:2023-11-03 17:50:02 24 4
gpt4 key购买 nike

Ruby 中 bool 数据类型的大小是多少?关于 Ruby Forum 的讨论很长对此,我没有得到最终的答案。

另外,我怎样才能找到它的大小。

比如我把它存储在一个数组中,需要多少内存

a=[true, true]

对比

a=[1,1]

最佳答案

序列化告诉我们

Marshal.dump([true,true]).length # => 6
Marshal.dump(true).length # => 3

Marshal.dump([1,1]).length # => 8
Marshal.dump(1).length # => 4

我很确定这个值并不代表实际内存使用情况,但是 [true,true] 似乎比 [1,1] 更有效。

关于ruby - Ruby 中 bool 值的大小是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26457842/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com