CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2005
    Posts
    200

    [RESOLVED] How to serialise objects to memory?

    I would like to save in-game data like player's health, ammo power etc into memory.

    The reason is that the game is split into states with each level represented by a state. When a level loads, there will be a state change and all objects of the previous state will be released and when the new level loads, the objects are recreated and reinitialized with original values.

    Hence there is a need to save gameplay data and restore them in the new level.

    The resources i have come across give alot of info on serializing to file using streams. But there is little information on serializing to memory using streams.

    How do I serialize object data into memory?

  2. #2
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: How to serialise objects to memory?

    The data is already in memory, correct ? Or is it on disk ?

    If the data storage is structured, then you should be able to just assign the stored data to the structures and start using it, what is the problem >?
    Regards,
    Ramkrishna Pawar

  3. #3
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: How to serialise objects to memory?

    I agree with Krishnaa that you should just store copies of the objects in memory, without serializing, but just for the record: You can use what you learned about serializing to file using streams to serialize them to a string, using the stringstream class. Then you can store the serialized string.
    More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf

    Premature optimization is the root of all evil --Donald E. Knuth


    Please read Information on posting before posting, especially the info on using [code] tags.

  4. #4
    Join Date
    Apr 2005
    Posts
    200

    Re: How to serialise objects to memory?

    yes, the data is in memory.

    Well i guess i'll use structures instead. Thanks all for the advice

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured