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 memory does a data table occupy than what would be needed simply to store a properly typed array of each column of data?
I guess there will be some basic table overhead, plus some amount per column, and then again an additional amount per row.
So can anyone give an estimate (and, I guess, explanation!) of each/any of these three kinds of overhead?
Well, don’t forget that a
DataTablestores 2? 3? versions of the data – original and updated (possibly one other?). It also has a lot of references since it is cell-based, and boxing for any value-types. It would be hard to quantify the exact memory…Personally, I very rarely use
DataTable– typed POCO classes are a much more sensible bet in my view. I wouldn’t use an array (directly), though –List<T>orBindingList<T>or similar would be far more common.As a crude measure, you could create a lot of tables etc and look at the memory usage; for example, the following shows a ~4.3 factor – i.e. more than 4 times as expensive, but obviously that depends a lot on the number of columns vs rows vs tables etc:
vs
(based on)