如何在 Scala 中使用原语? [英] How can I use primitives in Scala?

查看:58
本文介绍了如何在 Scala 中使用原语?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在 Scala 中使用原语吗?

Can I use primitives in Scala?

用例用于存储数十亿个整数,因此 4 个字节(对于 int)和 16 个字节(对于整数)之间的区别很重要.

The use case is for storing billions of ints, so the difference between 4 bytes (for an int) and 16 bytes (for an Integer) is important.

推荐答案

如果你想让 Scala 存储未装箱的原语,你可以使用 Array[Int] 但不要使用任何很酷的 Scala 收集方法它(因为它会强制拳击).

If you want Scala to store unboxed primitives, you could use Array[Int] but refrain from using any cool Scala collection method on it (because it will force boxing).

如果您要寻找原语类型的不可变集合,您可以查看 Debox,它提供了专门的缓冲区、集合和映射.该项目仍在发展中,但非常有前途.

If you look for immutable collections of primitives types, you can have a look at Debox, which provides specialised Buffers, Sets and Maps. The project is still evolving but it is very promising.

这篇关于如何在 Scala 中使用原语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆