Hi everyone. Is there a document about the size of...
# getting-started
k
Hi everyone. Is there a document about the size of each data type? I would like to know the size of a data class containing string, int, and boolean types. I don’t know the encoding type. I only used English. Thanks.
c
The primitive types are all described here, including the typical size of each value. Note that it might vary based on the platform
k
I’m looking into the exact memory size of my data class. Guess it’s really depends on the platform. I’m thinking of capturing heap dump with android studio and checking the shallow size of the data class. Do you think it’s worth it? @Casey Brooks
k
On recent JVM targets, strings are stored as ISO-8859-1 (one byte per character) if its content consists solely of characters in that character set. Otherwise, it is stored as UTF-16 (mostly two bytes per character, or more if using certain characters such as emojis). However, you said that you want to check the shallow size of the data class, so the string representation is irrelevant. See https://www.baeldung.com/java-size-of-object for some more info.
k
Thank you for the detailed explanation! The additional info link you provided also gave me valuable insights into the issue I was curious about. Thanks again! @Klitos Kyriacou