tags:

views:

60

answers:

1

In C#, how can you calculate the size of a datatable object in memory?

We're using this to store various data groups, and would like to perform some logging/monitoring to aid in tuning the system.

However one of the pieces of information we need is the size of the datatable object.

Any ideas?

A: 

I just had a conversation with a coworker recently about this subjecy. He stated that DataTables first allocate enough memory for 1 record, once you try to exceed that it allocates enough for 2 records, once you exceed that it doubles the total allocation again... this continues adnauseum.

The best way to figure out the relative amount of memory (in terms of rows) is to estimate your largest expected row count, find the highest power of 2 that corresponds to that number: e.g. 2,4,8,16,32,64,128,...,1048576,...etc.

Jason D