I am writing an application in .NET 4.0 C#. I am placing objects in the .net httpruntime cache and want to produce some stats on it. I would like to know the size of the object before it put in to cache and the size of it in cache. How can I measure this? Is it serialized when put in to cache and if so what type of serialization is used?
The HTTP Runtime Cache does not serialize data at all, it just places it in a hash table:
There are several methods to get or estimate the size of a .NET object in memory:
It's not possible to directly know the number of bytes consumed by a .NET object: