/// <summary> /// Allocates a block of memory at least as large as the amount requested. /// </summary> /// <param name="bytes">The number of bytes you want to allocate.</param> /// <returns>A pointer to a block of memory at least as large as bytes</returns> /// <remarks> /// This method uses an alternate method for allocating memory (VirtualAlloc in Windows). The allocation /// granularity is the page size of the system (usually 4K). Blocks allocated with this method may also /// be protected using the ProtectBlock method. /// </remarks> public static IntPtr AllocateLarge(ulong bytes) { IntPtr block = SafeNativeMethods.VirtualAlloc(IntPtr.Zero, new UIntPtr(bytes), NativeConstants.MEM_COMMIT, NativeConstants.PAGE_READWRITE); if (block == IntPtr.Zero) { throw new OutOfMemoryException("VirtualAlloc returned a null pointer"); } if (bytes > 0) { MemoryPressureManager.AddMemoryPressure((long)bytes); } return(block); }