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

◆ MemoryFailPoint()

System.Runtime.MemoryFailPoint.MemoryFailPoint ( int sizeInMegabytes)
inline

Definition at line 54 of file MemoryFailPoint.cs.

55 {
56 if (sizeInMegabytes <= 0)
57 {
58 throw new ArgumentOutOfRangeException("sizeInMegabytes", SR.ArgumentOutOfRange_NeedNonNegNum);
59 }
60 ulong num = (_reservedMemory = (ulong)((long)sizeInMegabytes << 20));
61 ulong num2 = (ulong)(Math.Ceiling((double)num / (double)s_GCSegmentSize) * (double)s_GCSegmentSize);
62 if (num2 >= s_topOfMemory)
63 {
64 throw new InsufficientMemoryException(SR.InsufficientMemory_MemFailPoint_TooBig);
65 }
66 ulong num3 = (ulong)(Math.Ceiling((double)sizeInMegabytes / 16.0) * 16.0);
67 num3 <<= 20;
68 for (int i = 0; i < 3; i++)
69 {
70 if (!CheckForAvailableMemory(out var availPageFile, out var totalAddressSpaceFree))
71 {
72 return;
73 }
74 ulong memoryFailPointReservedMemory = MemoryFailPointReservedMemory;
75 ulong num4 = num2 + memoryFailPointReservedMemory;
76 bool flag = num4 < num2 || num4 < memoryFailPointReservedMemory;
77 bool flag2 = availPageFile < num3 + memoryFailPointReservedMemory + 16777216 || flag;
78 bool flag3 = totalAddressSpaceFree < num4 || flag;
79 long num5 = Environment.TickCount;
81 {
82 CheckForFreeAddressSpace(num2, shouldThrow: false);
83 }
84 bool flag4 = (ulong)LastKnownFreeAddressSpace < num2;
85 if (!flag2 && !flag3 && !flag4)
86 {
87 break;
88 }
89 switch (i)
90 {
91 case 0:
92 GC.Collect();
93 break;
94 case 1:
95 if (flag2)
96 {
97 UIntPtr numBytes = new UIntPtr(num2);
99 }
100 break;
101 case 2:
102 if (flag2 || flag3)
103 {
104 InsufficientMemoryException ex = new InsufficientMemoryException(SR.InsufficientMemory_MemFailPoint);
105 throw ex;
106 }
107 if (flag4)
108 {
109 InsufficientMemoryException ex2 = new InsufficientMemoryException(SR.InsufficientMemory_MemFailPoint_VAFrag);
110 throw ex2;
111 }
112 break;
113 }
114 }
115 AddToLastKnownFreeAddressSpace((long)(0L - num));
117 {
118 CheckForFreeAddressSpace(num2, shouldThrow: true);
119 }
122 }
static unsafe void CheckForFreeAddressSpace(ulong size, bool shouldThrow)
static unsafe void GrowPageFileIfNecessaryAndPossible(UIntPtr numBytes)
static unsafe bool CheckForAvailableMemory(out ulong availPageFile, out ulong totalAddressSpaceFree)
static long AddMemoryFailPointReservation(long size)
static void AddToLastKnownFreeAddressSpace(long addend)
static readonly ulong s_topOfMemory
static readonly ulong s_GCSegmentSize

References System.Runtime.MemoryFailPoint._mustSubtractReservation, System.Runtime.MemoryFailPoint._reservedMemory, System.Runtime.MemoryFailPoint.AddMemoryFailPointReservation(), System.Runtime.MemoryFailPoint.AddToLastKnownFreeAddressSpace(), System.SR.ArgumentOutOfRange_NeedNonNegNum, System.Math.Ceiling(), System.Runtime.MemoryFailPoint.CheckForAvailableMemory(), System.Runtime.MemoryFailPoint.CheckForFreeAddressSpace(), System.GC.Collect(), System.Runtime.MemoryFailPoint.GrowPageFileIfNecessaryAndPossible(), System.SR.InsufficientMemory_MemFailPoint, System.SR.InsufficientMemory_MemFailPoint_TooBig, System.SR.InsufficientMemory_MemFailPoint_VAFrag, System.L, System.Runtime.MemoryFailPoint.LastKnownFreeAddressSpace, System.Runtime.MemoryFailPoint.LastTimeCheckingAddressSpace, System.Runtime.MemoryFailPoint.MemoryFailPointReservedMemory, System.Runtime.MemoryFailPoint.s_GCSegmentSize, System.Runtime.MemoryFailPoint.s_topOfMemory, and System.Environment.TickCount.