2014-02-17 51 views
0

如何计算缓存密钥存储在c#中时占用的内存空间如何计算c#中的缓存密钥存储所消耗的内存空间如何计算c#缓存密钥存储时消耗的内存空间?

+0

确定一个特定的对象在.NET内存中占用多少内存是非常困难和不准确的 - 有很多因素影响实现细节。你想在这里完成什么? – vcsjones

+0

我只是想插入一个缓存键,然后我计算有多少空间消耗该缓存键。 –

回答

0

您可以通过查询垃圾收集器和缓存对象找到你的应用程序的内存一般信息。我不确定如何找到缓存使用的确切内存,但这是理解应用程序内存消耗的一个步骤。

// returns the memory consumption of this process 
// This includes active objects, objects to be disposed, and items within cache. 
// Setting the parameter to 'true' will force a garbage collection before returning the results 
GC.GetTotalMemory(false); 

// This shows the maximum size available to the cache 
// These limits can be set within the app.config/web.config files 
Cache.EffectivePrivateBytesLimit;