void Pad8() { long count = counts[0]; long lastMem = GC.GetTotalMemory(false); Item8 temp = null; Item8 test; while (count > 0) { // Allocate a block test = new Item8(); long curMem = GC.GetTotalMemory(false); if (curMem == lastMem + 4096) { // Add the block to the keep list test.next = head8; head8 = test; count--; } else { // Store the block in the temp list test.next = temp; temp = test; } lastMem = curMem; } }
public void Pad() { Log.Info("HeapPadder.Pad"); try { UpdateFromConfig(); Log.Info("The highest generation is " + GC.MaxGeneration); long curMem = GC.GetTotalMemory(false); long startMem = curMem; Log.Info("Pad started, memory = " + (curMem / 1024) + " KB"); head8 = null; head16 = null; head24 = null; for (int i = 0; i < heads.Length; i++) { heads[i] = null; } GC.Collect(); curMem = GC.GetTotalMemory(false); long minMem = curMem; Log.Info("After discard and collect, memory = " + (curMem / 1024) + " KB"); // Do the small sizes with custom classes Pad8(); Pad16(); Pad24(); // Do the rest of the sizes with arrays of object for (int i = 3; i < lengths.Length; i++) { PadArray(i); } curMem = GC.GetTotalMemory(false); Log.Info("After padding, memory = " + (curMem / 1024) + " KB"); GC.Collect(); curMem = GC.GetTotalMemory(false); Log.Info("After final collect, memory = " + (curMem / 1024) + " KB"); ScreenMessages.PostScreenMessage("HeapPadder, initial mem: " + ((int)startMem / 1024).ToString("F0") + ", minMem: " + ((int)minMem / 1024).ToString("F0") + ", final mem: " + ((int)curMem / 1024).ToString("F0"), 10f, ScreenMessageStyle.UPPER_CENTER); } catch (Exception e) { Log.Info(e.ToString()); } }