gpt4 book ai didi

javascript - 在 ES5 中使用 JS 对象作为集合时值类型的效率

转载 作者:行者123 更新时间:2023-12-03 05:33:25 25 4
gpt4 key购买 nike

在 ES5 中使用对象作为集合时,例如:

var thingsSeen = {};
thingsSeen["cat"] = true;
thingsSeen["dog"] = true;

使用数字而不是 bool 值作为值有什么区别吗?哪个在实践中更好?为什么?

最佳答案

您可以将 bool 值存储在单个位中。您需要 64 位的数字。

然后不同的实现可能会使用额外的内存,例如 bool 值的整个字节。但很可能该数字需要更多内存。

关于javascript - 在 ES5 中使用 JS 对象作为集合时值类型的效率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40835283/

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