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?