我们开发了一个航空公司模拟游戏,我们当前的结构将用户数据保存在一个XML文件中(以及所有游戏数据,如机场统计数据、飞机信息等)。
就性能和功能而言,在本地计算机上存储此数据的最佳方式是什么?我听到了双方的一些意见,但没有真正具体的或以实例为后盾的答案。尽管我们的原始数据XML较小(<150KB),但保存的游戏非常大(3-10MB),并且跨越几千行或多或少的无组织数据。
想法、建议或建议?
发布于 2013-03-16 23:01:05
如果您不需要手动编辑文件,您可以尝试使用BinaryFormatter来序列化和反序列化您的数据,这应该比XmlSerializer快得多。
下面是一个如何使用它的示例。
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;
}
}
}发布于 2013-03-16 22:57:01
如果您将数据保存在XML文件中,那么可以考虑为它创建一个XML数据库,比如Oracle /BaseX/ BerkleyDB。您可以使用DB进行数据操作,也可以使用XQuery来查询XML。Berkley DB XML数据库具有良好的性能。
此外,如果您的用户数据、机场统计数据等具有行与行不同的信息,则应使用XML数据库。
如果您的数据模型结构良好,则可以使用MySql或PostGreSql等开源数据库来处理所有数据。
在这里,这两种方法都可以很好地满足您添加/更新数据所需的数据库大小。在选择数据存储库类型时,应该考虑您的数据模型。
如果您选择XML数据库,您的数据访问/保存代码可能会被重用。
如果您选择RDBMS,则应该为您的应用层编写代码。
希望这个洞察和进一步的学习会对你有所帮助。
https://stackoverflow.com/questions/15450564
复制相似问题