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

Do they take up the same amount of memory? Array is an abstract class, so it doesn't carry any object header cost? The same for other arrays of Java primitives in Scala?

PS: I read somewhere that Scala stores them as primitive arrays in the JVM, but now I'm confused.

+3


source to share


2 answers


Scala Array [T] is exactly represented as Java T [], no overhead. They generate the same bytecode. You also have the operations provided by ArrayOps, but this is an implicit conversion that does not affect the representation of the pure array [T].



+7


source


If you are not interested in the potential difference in multiple bytes (Scala Array

vs Java Array

), they are about the same in terms of memory usage, since Scala Int

is represented as a Java primitive Int

:



http://www.scala-lang.org/api/current/index.html#scala.Int

0


source







All Articles