Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ CreateView()

static MemoryMappedView System.IO.MemoryMappedFiles.MemoryMappedView.CreateView ( SafeMemoryMappedFileHandle memMappedFileHandle,
MemoryMappedFileAccess access,
long offset,
long size )
inlinestatic

Definition at line 60 of file MemoryMappedView.cs.

61 {
62 ValidateSizeAndOffset(size, offset, GetSystemPageAllocationGranularity(), out var newSize, out var extraMemNeeded, out var newOffset);
63 global::Interop.CheckForAvailableVirtualMemory(newSize);
64 SafeMemoryMappedViewHandle safeMemoryMappedViewHandle = global::Interop.MapViewOfFile(memMappedFileHandle, MemoryMappedFile.GetFileMapAccess(access), newOffset, new UIntPtr(newSize));
65 if (safeMemoryMappedViewHandle.IsInvalid)
66 {
67 safeMemoryMappedViewHandle.Dispose();
69 }
70 global::Interop.Kernel32.MEMORY_BASIC_INFORMATION lpBuffer = default(global::Interop.Kernel32.MEMORY_BASIC_INFORMATION);
71 global::Interop.Kernel32.VirtualQuery(safeMemoryMappedViewHandle, ref lpBuffer, (UIntPtr)(ulong)Marshal.SizeOf(lpBuffer));
72 ulong num = (ulong)lpBuffer.RegionSize;
73 if ((lpBuffer.State & 0x2000u) != 0 || num < newSize)
74 {
75 IntPtr intPtr = global::Interop.VirtualAlloc(safeMemoryMappedViewHandle, (UIntPtr)((newSize != 0L) ? newSize : num), 4096, MemoryMappedFile.GetPageAccess(access));
76 int lastPInvokeError = Marshal.GetLastPInvokeError();
77 if (safeMemoryMappedViewHandle.IsInvalid)
78 {
79 safeMemoryMappedViewHandle.Dispose();
80 throw System.IO.Win32Marshal.GetExceptionForWin32Error(lastPInvokeError);
81 }
82 lpBuffer = default(global::Interop.Kernel32.MEMORY_BASIC_INFORMATION);
83 global::Interop.Kernel32.VirtualQuery(safeMemoryMappedViewHandle, ref lpBuffer, (UIntPtr)(ulong)Marshal.SizeOf(lpBuffer));
84 num = (ulong)lpBuffer.RegionSize;
85 }
86 if (size == 0L)
87 {
88 size = (long)num - extraMemNeeded;
89 }
90 safeMemoryMappedViewHandle.Initialize((ulong)(size + extraMemNeeded));
91 return new MemoryMappedView(safeMemoryMappedViewHandle, extraMemNeeded, size, access);
92 }
static void ValidateSizeAndOffset(long size, long offset, long allocationGranularity, out ulong newSize, out long extraMemNeeded, out long newOffset)
MemoryMappedView(SafeMemoryMappedViewHandle viewHandle, long pointerOffset, long size, MemoryMappedFileAccess access)
static Exception GetExceptionForLastWin32Error(string path="")
static Exception GetExceptionForWin32Error(int errorCode, string path="")
static int SizeOf(object structure)
Definition Marshal.cs:697

References System.IO.MemoryMappedFiles.MemoryMappedView.MemoryMappedView(), System.Runtime.InteropServices.SafeHandle.Dispose(), System.IO.Win32Marshal.GetExceptionForLastWin32Error(), System.IO.Win32Marshal.GetExceptionForWin32Error(), System.IO.MemoryMappedFiles.MemoryMappedFile.GetFileMapAccess(), System.Runtime.InteropServices.Marshal.GetLastPInvokeError(), System.IO.MemoryMappedFiles.MemoryMappedFile.GetPageAccess(), System.IO.MemoryMappedFiles.MemoryMappedView.GetSystemPageAllocationGranularity(), System.Runtime.InteropServices.SafeBuffer.Initialize(), Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid.IsInvalid, System.L, System.newSize, System.offset, System.Runtime.InteropServices.Marshal.SizeOf(), and System.IO.MemoryMappedFiles.MemoryMappedView.ValidateSizeAndOffset().

Referenced by System.IO.MemoryMappedFiles.MemoryMappedFile.CreateViewAccessor(), and System.IO.MemoryMappedFiles.MemoryMappedFile.CreateViewStream().