Binary serialization in C # - Add file


I'm doing a project where I'm recording user inputs to a list and serializing this information to a binary file. So far I can record the users inputs on a gamepad in a LIST of padStates and the serialize this information but at the minute it will only serialize AFTER the session has ended. In other words, I have to have the padstate LIST in memory for the entire time that the recording is running. Obviously this isn't ideal since I'm taking up memory and when it gets too big it will crash the program.

I was thinking it might be possible to open a filestream when a class is instantiated and periodically write the LIST to a file; say every 600 frames or so. Once this is serialized I can then clear the list and start populating it again.

Is this actually possible? I guess it's appending data to the file but none of the books I have talk about this..

If anyone can point me in the direction that'd be great.

Appending data to a file is done using FileMode.Append.

This can be specified when constructing a FileStream object.

FileStream Constructor