Discussion in 'Mac Programming' started by mdeh, Mar 3, 2009.

  1. macrumors 6502

    Jan 3, 2009
    Hi everyone,
    I am up to Archiving in Kochan's book. Being totally new to the concept of serialization, spent most of the day just trying to familiarizing myself with the basic concepts. So, XML and plists have been seen and digested, the concepts of sending files to other computers, understood ( I think).

    But...I would like to try and put into some sort of perspective.
    May I just ask this. What would members of the list say is the commonest tasks that one would use Archiving for? Versus, for example, just saving a file ( as in Textfile.rtf save).

  2. macrumors 6502

    Apr 24, 2008
    Serialization is usually used to persist the entire state of a program, so that when it's relaunched, it can continue from the state where it left.
  3. Moderator emeritus


    Jun 15, 2000
    An example is the ~/Library/StickiesDatabase file. It's just a serialized array with objects for each Stickies note.
  4. macrumors 68040


    Jan 10, 2005
    Dallas, TX
    It's pretty much been covered, but I thought I'd add my 2 cents. Serialization is any means by which you encode the state of data internal to your program such that the state can be restored. There's no reason that you cannot serialize in a text-only format, but it may be less efficient than a binary serialization (i.e. to have the ascii representation of a 4-byte integer in decimal, it could take 11 bytes. Wrap that in XML tags and it could be ~50-60 bytes). XML is a text-based serialization that has the added benefit of being cross-platform and well-understood. It is possible to write your serialization and deserialization routines such that the binary data can be used on different platforms, but it requires much greater care than if you were to just generate a binary file that could be re-read on the same platform.

    In an Object-Oriented language, serialization generally applies per-object, as a means of taking the in-memory state of an object and allowing it to be persisted via an on-disk file, a row in a database, etc., so this state can be restored later.

    I don't know what, exactly, would be the most common, but I can give some examples... if you are playing a video game, and you can save your game, then all of the game state must be saved in a file so it can be reloaded. Or XCode... there's all of the textual data for your code, but there's also a project file that XCode maintains that keeps track of what files you have open, etc. so that state can be restored when you re-open the project later.

  5. thread starter macrumors 6502

    Jan 3, 2009
    Lee, Sander and Kainjow...thank you all very much for putting this into perspective.

Share This Page