简体   繁体   中英

How do you calculate the size of a datatable object?

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?

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: eg 2,4,8,16,32,64,128,...,1048576,...etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM