Search code examples
c#serializationinformation-retrieval

How should I save my data?


I have two structs like so:

public struct KeyLog
{
    Keys key;
    DateTime time;
}

public struct MouseLog
{
    MouseEvents mouse;
    Point coordinates;
    DateTime time;
}

For every keyboard key press and mousebutton click I wish to save this data but I do not know which way would be the most efficient to store/handle it in? Are there better ways to handle the data - I'm not sure if using two structs is better than merging both into one?

Edit: I'm doing a keyboard & mouse statistic application that'll store the amount of key press & mouse clicks as well as what button was pressed, where and when for my computer and I would want to save this data every time a button is pressed. Not necessarily write to disk every time but at least store it in memory till I want to save it to disk.

Edit: I thought that if I keep the two structs separate I won't create too much dead data when I store them, and then I can easily search/sort if I keep them separate. Thoughts?


Solution

  • A BinaryFormatter would give you the smallest compression. Also if you change them to classes, you could have a base class with a DateTime time field.