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
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
0 comments:
Post a Comment