ikvmnet / ikvm

A Java Virtual Machine and Bytecode-to-IL Converter for .NET
Other
1.22k stars 111 forks source link

Adjust memory pressure for Unsafe.allocateMemory #354

Closed wasabii closed 1 year ago

wasabii commented 1 year ago

System.GC.AddMemoryPressure and System.GC.RemoveMemoryPressure should be updated when Unsafe.allocateMemory is called, Unsafe.reallocateMemory and Unsafe.freeMemory().

We do this by storing an sizeof(IntPtr) header at the beginning of the allocate block of memory, so we can record the original length to remove upon deallocation.