DataTable
さて、店舗2であることを忘れないでください。3? データのバージョン - 元のバージョンと更新されたバージョン (おそらく別のバージョン?)。また、セルベースであるため、多くの参照があり、任意の値タイプのボックス化が行われます。正確なメモリを定量化するのは難しいでしょう...
個人的には、私はめったに使用しませんDataTable
- 型付けされた POCO クラスは、私の見解でははるかに賢明な賭けです。ただし、配列を(直接)使用することはありません-List<T>
またはBindingList<T>
同様の方法がはるかに一般的です。
大まかな尺度として、多くのテーブルなどを作成してメモリ使用量を調べることができます。たとえば、次の例では最大 4.3 の係数が示されています。つまり、4 倍以上のコストがかかりますが、これは明らかに、列数、行数、テーブル数などに大きく依存します。
// takes **roughly** 112Mb (taskman)
List<DataTable> tables = new List<DataTable>();
for (int j = 0; j < 5000; j++)
{
DataTable table = new DataTable("foo");
for (int i = 0; i < 10; i++)
{
table.Columns.Add("Col " + i, i % 2 == 0 ? typeof(int)
: typeof(string));
}
for (int i = 0; i < 100; i++)
{
table.Rows.Add(i, "a", i, "b", i, "c", i, "d", i, "e");
}
tables.Add(table);
}
Console.WriteLine("done");
Console.ReadLine();
対
// takes **roughly** 26Mb (taskman)
List<List<Foo>> lists = new List<List<Foo>>(5000);
for (int j = 0; j < 5000; j++)
{
List<Foo> list = new List<Foo>(100);
for (int i = 0; i < 100; i++)
{
Foo foo = new Foo { Prop1 = "a", Prop3 = "b",
Prop5 = "c", Prop7 = "d", Prop9 = "e"};
foo.Prop0 = foo.Prop2 = foo.Prop4 = foo.Prop6 = foo.Prop8 = i;
list.Add(foo);
}
lists.Add(list);
}
Console.WriteLine("done");
Console.ReadLine();
(に基づく)
class Foo
{
public int Prop0 { get; set; }
public string Prop1 { get; set; }
public int Prop2 { get; set; }
public string Prop3 { get; set; }
public int Prop4 { get; set; }
public string Prop5 { get; set; }
public int Prop6 { get; set; }
public string Prop7 { get; set; }
public int Prop8 { get; set; }
public string Prop9 { get; set; }
}