This is a mirror of official site: http://jasper-net.blogspot.com/

NET Hidden Gems - Memory fail points

| Wednesday, July 21, 2010
I am embarking in a series of mini post called .NET hidden gems, not necessarily new bits but usually unknown. They are dedicated to those small features and components that are not commonly used but can deliver interesting value in certain scenarios.
Today I am going to show you some functions that can help you to understand the memory state of your application when you need to store large objects.
The first hidden gem is the MemoryFailPoint object, this can be accessed through the System.Runtime namespace.
The main function of it is validating that there is enough memory to perform an operation.

[SecurityCritical]
public MemoryFailPoint(int sizeInMegabytes);
It is very easy to use it, just create an instance when you need the memory:
//
// Do I have enough memory to run this method?
//
System.Runtime.MemoryFailPoint CheckForMemory = new System.Runtime.MemoryFailPoint(1000);

Internally, it checks the global memory status of the process; if it does not have enough it will perform a full collection.

Read more: MSDN Utopia

Posted via email from .NET Info

0 comments: