private static IntPtr Allocate(long bytes, bool allowRetry) { IntPtr block; try { if (bytes >= largeBlockThreshold) { block = Memory.AllocateLarge((ulong)bytes); } else { block = Memory.Allocate((ulong)bytes); } } catch (OutOfMemoryException) { if (allowRetry) { Utility.GCFullCollect(); return(Allocate(bytes, false)); } else { throw; } } return(block); }
private static IntPtr Allocate(long bytes, bool allowRetry) { IntPtr block; try { if (bytes >= largeBlockThreshold) { block = Memory.AllocateLarge((ulong)bytes); } else { block = Memory.Allocate((ulong)bytes); } } catch (OutOfMemoryException) { if (allowRetry) { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); return(Allocate(bytes, false)); } else { throw; } } return(block); }