2

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?

Eric J.
  • 147,927
  • 63
  • 340
  • 553
amateur
  • 43,371
  • 65
  • 192
  • 320

1 Answers1

6

The HTTP Runtime Cache does not serialize data at all, it just places it in a hash table:

What is the default serialization used by the ASP.net HttpRuntime.Cache

There are several methods to get or estimate the size of a .NET object in memory:

How to get object size in memory?

https://stackoverflow.com/a/1128674/141172

It's not possible to directly know the number of bytes consumed by a .NET object:

http://blogs.msdn.com/b/cbrumme/archive/2003/04/15/51326.aspx

Community
  • 1
  • 1
Eric J.
  • 147,927
  • 63
  • 340
  • 553