Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory comparison of Scala's Array[Int] v/s int[] in Java?

Tags:

java

jvm

scala

Do they take the same amount of memory? Array is an abstract class so does it incur any object header cost? Is it same for other arrays of Java primitives in Scala?

PS: I read somewhere that Scala stores them as primitive arrays in JVM but now am confused.

like image 576
Dragonborn Avatar asked May 18 '26 04:05

Dragonborn


1 Answers

Scala's Array[T] is exactly represented as Java's T[], there's no overhead. They generate the same bytecode. You additionally have the operations provided by ArrayOps, but it is an implicit conversion, which does not affect the pure Array[T] representation.

like image 154
ponythewhite Avatar answered May 20 '26 19:05

ponythewhite



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!