public static bool EnsureMemoryAvailability(int expectedSizeMegaBytes) { if (expectedSizeMegaBytes < 0) { throw new ArgumentException("Param expectedSizeBytes should be positive", "expectedSizeMegaBytes"); } bool available = true; MemoryFailPoint p = null; try { p = new MemoryFailPoint(expectedSizeMegaBytes); } catch(InsufficientMemoryException) { available = false; } finally { if(p != null) { try { p.Dispose(); } catch(Exception) { // ignored } } } return available; }
public virtual bool IsSpaceAvailable(int sizeInMb) { if (sizeInMb < 1) return true; bool isAvailable = true; MemoryFailPoint _memoryFailPoint = null; try { _memoryFailPoint = new MemoryFailPoint(sizeInMb); } catch (InsufficientMemoryException) { isAvailable = false; } catch (NotImplementedException) { _logger.Warn("MemoryFailPoint is not implemented on this platform. The MemoryManager.IsSpaceAvailable() will just return true."); } finally { if (_memoryFailPoint != null) _memoryFailPoint.Dispose(); } return isAvailable; }
public static void MemoryFailPointTestNoThrow() { MemoryFailPoint memFailPoint = null; memFailPoint = new MemoryFailPoint(1); memFailPoint.Dispose(); memFailPoint = new MemoryFailPoint(2); memFailPoint.Dispose(); }