• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HD space taken up by serialization

 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.
reply
    Bookmark Topic Watch Topic
  • New Topic