Reputation: 2393
We develop an airline simulation game, and our current structure saves user data in an XML file (as well as all game data such as airport statistics, aircraft information, etc).
Performance and functionality-wise, what is the best way to store this data on the local machine? I have heard some of both sides but no real concrete or example-backed answers. Although our raw data XMLs are smaller (<150KB), the saved games are quite large (3-10MB) and span several thousand lines of more or less unorganized data.
Thoughts, suggestions, or recommendations?
Upvotes: 1
Views: 976
Reputation: 6466
If you don't need to be able to edit the files by hand you could try using the BinaryFormatter to serialize & deserialize your data, should be a lot faster than the XmlSerializer.
Here is an example of how to use it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication2
{
[Serializable()]
public class Child
{
public string Property1 { get; set; }
}
[Serializable()]
public class TestClass
{
public int Property1 { get; set; }
public string Property2 { get; set; }
public DateTime Property3 { get; set; }
public Child Child { get; set; }
}
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
TestClass testClass = new TestClass()
{
Property1 = 1,
Property2 = "test",
Property3 = DateTime.Now,
Child = new Child()
{
Property1 = "test",
}
};
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
formatter.Serialize(memoryStream, testClass);
memoryStream.Position = 0;
TestClass deserialized = formatter.Deserialize(memoryStream) as TestClass;
}
}
}
Upvotes: 3
Reputation: 1764
If you save your data in XML file, then consider a XML Database for it Like Oracle BerkleyDB XML/BaseX/Sedna. You can use DB API for data manipulation and also can use XQuery for querying that XML. Berkley DB XML Database is good in performance.
Also you should use XML Database if your user data, airport statistics etc have information which can vary row to row.
And if your data model is well structured, then you can use open source database like MySql or PostGreSql to handle all your data.
Here, both will work fine with your expected database size for data addition/updation. You should consider your data model for choosing the data repository type.
If you choose XML Database your data access/save code may be reused.
If you choose RDBMS, you should code for your application layer.
Hope, this insight and further study will help you.
Upvotes: 0