, OwenP , System.Runtime.MemoryFailPoint.
: public MemoryFailPoint(int sizeInMegabytes), AverageFrameSize , . :
MemoryFailPoint 16 . 16 16 , 16 .
, MemoryFailPoint , , , !
, , OP.
, , , MemoryFailPoint , . , , , . ( MemoryFailPoint !)
"" Dispose(). , MemoryFailPoint -instance , , .
( " " , . , .)
. , MemoryFailPoint , . ( - , MSDN.)
( ) :
const int FrameSizeInMegabytes = 10;
const int FrameSizeInBytes = FrameSizeInMegabytes << 20;
bool TryCreateImageBuffer(int numberOfImages, out byte[,] imageBuffer)
{
if (numberOfImages < 0 || numberOfImages > 0x7FFFFFC7)
throw new ArgumentOutOfRangeException("numberOfImages",
"Outside allowed range: 0 <= numberOfImages <= 0x7FFFFFC7");
MemoryFailPoint memoryReservation = null;
try
{
memoryReservation =
new MemoryFailPoint(FrameSizeInMegabytes * numberOfImages);
}
catch (InsufficientMemoryException ex)
{
imageBuffer = null;
return false;
}
imageBuffer = new byte[numberOfImages, FrameSizeInBytes];
memoryReservation.Dispose();
return true;
}
0x7FFFFFC7 - , , MSDN .
( MemoryFailPoint) :
const int AverageFrameSizeInMegabytes = 10;
MemoryFailPoint GetMemoryFailPointFor(int numberOfImages)
{
MemoryFailPoint memoryReservation = null;
try
{
memoryReservation =
new MemoryFailPoint(AverageFrameSizeInMegabytes * numberOfImages);
}
catch (InsufficientMemoryException ex)
{
return null;
}
return memoryReservation;
}
( ), MemoryFailPoint . ( , .)
: ""
"" , ( ). , MemoryFailPoint , , , ( "" ) , MemoryFailPoint. MemoryFailPoint (, ), () "" . ( MemoryFailPoint, .). "", , MemoryFailPoint .
, "" . , , , :
// Note that multiple threads can still ---- on our free chunk of address space, which can't be easily solved.
, .
2GB .
, , <gcAllowVeryLargeObjects>, , .
, , OP. , MemoryFailPoint , , - -. , OutOfMemoryException, , , OP.
, , , AllocateUserPhysicalPages, , , . OS , , , ...