Get the size of a DataTable or ArrayList in memory

There are several articles on How to get the size of an object in memory? but they do not explain how to get the size of an object in memory.

when i use:

System.Runtime.InteropServices.Marshal.SizeOf (arrayListObject)

i get the error:

Enter 'System.Collections.ArrayList' cannot be marshaled as an unmanaged composition; no significant size or offset can be calculated.

I also can not get the amount of free memory, because I want to perform this calculation in web applications with a large number of threads, so you need to know exactly how much memory is required for a particular object.

+3
source share
3 answers
+2

- : .

+1

What about serializing a DataTable and then checking its length?

System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream stream = new System.IO.MemoryStream();
formatter.Serialize(stream, YourDataTable);
long length = stream.Length;
0
source

Source: https://habr.com/ru/post/1735410/


All Articles