M
M
Maxim2017-04-15 16:47:52
Database
Maxim, 2017-04-15 16:47:52

Store many objects of the same type on disk?

JSON
{
  "count": 10, //количество элементов
  "Event": 
  [//GameEvent Array
    {
      "ID": 0,
      "Text": "Hello!"
      {//EventInfo
        "TimeOut": 0
      }
    }
    {
      "ID": 1,
      "Text": "I keep data."
      {
      "TimeOut": 42
      }
    }
    //...
  ]
}
C#
DataContract]
    public sealed class GameEvent
    {
        [DataMember]
        public EventInfo EventInfo { get; }
        [DataMember]
        public string Text { get; }

        internal GameEvent(string text, EventInfo ei)
        {
            Text = text;
            EventInfo = ei;
        }

        internal GameEvent(string text)
            : this(text, default(EventInfo))
        { }
    }

[DataContract()]
    public struct EventInfo
    {
        [DataMember]
        TimeSpan TimeOut;

        internal EventInfo(TimeSpan timeOut)
        {
            TimeOut = timeOut;
        }
    }


How to serialize a single object (GameEvent) by ID? (There are a lot of elements planned, and I don't want to keep them in memory.)
Maybe try a database? How to create it without installed special programs. And how to address it from the code?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Artamonov, 2017-04-15
@Got_Oxidus

Maybe try db? How to create it without installed special programs.

It depends on which database ..
If you store data in files, then it is better to use JSON

A
Artem, 2017-04-15
@devspec

Try https://github.com/google/protobuf
Cool stuff - very fast.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question