Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HD space taken up by serialization  RSS feed

 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Recently I changed the method of saving the data of a certain program. Instead of writing to a text file, I serialized the data. Saved in text format, the data files are about 60 kb, and serialized, the file is about 90 kb. Serialized, it takes up more HD memory, which seems strange to me. I was thinking about how to make smaller files.
Serialized, the data is saved in ArrayLists. Would saving the data in arrays instead of ArrayLists save memory?
From what I understand, whenever two String variables have the same value, the computer remembers the String only once, and remembers that those two references are references to the same object. Therefore, the memory taken up is the memory needed for the String, and for the two references to the String. Could it be that when serialized, two Strings are written to the file when there are two references, even if the references are references to the same String?
Are primitives, like int, remembered the same way as Strings? For example, if int a = 4 and int b = 4, does the computer remember the integer 4 once or twice?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Default serialisation saves a lot of metadata, as well as the actual data. It is possible to override default serialisation and one of the reasons one might do so is to use a more concise format.

Serialisation will not repeatedly write out the same object. It's smart enough to realise what it has already written.

Primitives are not objects and the whole concept of duplication is largely irrelevant to them.

Read the serialisation documentation for more information. Seriously, do read it - all your questions are almost certainly answered there.
 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!