开发者

Fast cleaning DataSet - reading xml files (C#)

开发者 https://www.devze.com 2023-01-17 00:38 出处:网络
I use a DataGrid to show a xml file. The Grid\'s DataSource is a DataSet.(using schema) Assembly assembly = Assembly.GetExecutingAssembly();

I use a DataGrid to show a xml file. The Grid's DataSource is a DataSet.(using schema)

            Assembly assembly = Assembly.GetExecutingAssembly();
            Stream stream = assembly.GetManifestResourceStream("XML_Reader.Resources.schema.xsd");
            XmlSchemaSet schemas = new XmlSchemaSet();
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ValidationType = ValidationType.Schema;
            settings.Schemas.Add(null, XmlReader.Create(stream));
            using (XmlReader reader = XmlR开发者_运维百科eader.Create(xmlFile, settings))
            {
                newDataSet.ReadXml(reader);
            }
            dataGrid.DataSource = newDataSet;

But when reading a new xml file, i need to clear the DataSet.(newDataSet.Clear();)

Because i read 'large' (40 Mb) xml files, clearing the DataSet is very slow.

How can i speed up this clearing?

Reading the file is also slow !

On a: Intel i7 950, 8 Gb, Win7 64-bit.


Why can't you just create new dataset and use that instead clearing old one? The old one will be garbage collected by .NET.


I suggest you use a new DataSet object for each file and avoid using DataSet.Clear() altogether. Just leave the old datasets to be cleared up by the garbage collector.


Let me answer my own question ;-))

A typed DataSet is simply a class you can instantiate like any other class.
There is no magic to anything generated by tools, those tools simply generate classes and you can use those classes the same way you use other classes.

Do NewDataSet d1 = new NewDataSet(); where you put the right class name there instead of "NewDataSet".

0

精彩评论

暂无评论...
验证码 换一张
取 消