What is the memory overhead of storing data in a .NET DataTable?

后端 未结 3 1696
旧时难觅i
旧时难觅i 2020-12-05 05:21

I\'m trying to get a handle on the amount of memory overhead associated with a .NET DataTable, and with individual DataRows within a table.
In other words, how much more

3条回答
  •  隐瞒了意图╮
    2020-12-05 05:28

    Overhead is pretty low if you don't define indexes on columns. You can get a pretty low memory footprint if you use string caching: Use a HashSet or Dictionary to use just 1 string instance of every string value. This sounds weird, but if you fetch data from a database, and you have multiple rows with the same string value (e.g. "ALFKI"), the string values are equal, but the string instances are not: the string is stored multiple times in memory. If you first use a HashSet for filtering out duplicate instances, you effectively use the same string instance for 1 string value everywhere in your datatable. This can greatly reduce memory footprint. Of course, if the string values are already statically defined somewhere (so not read from an outside source), it's not worth the effort.

提交回复
热议问题