public byte *Allocate(int size) { var memory = PlatformDetails.RunningOnPosix ? PosixElectricFencedMemory.Allocate(size) : Win32ElectricFencedMemory.Allocate(size); #if MEM_GUARD_STACK Allocs.TryAdd((IntPtr)memory, Tuple.Create(size, Environment.StackTrace)); #endif return(memory); }
public void Free(byte *p) { #if MEM_GUARD_STACK Tuple <int, string> _; if (Allocs.TryRemove((IntPtr)p, out _) == false) { var allocationsList = DoubleMemoryReleases.GetOrAdd((IntPtr)p, x => new ConcurrentSet <string>()); allocationsList.Add(Environment.StackTrace); } #endif if (PlatformDetails.RunningOnPosix) { PosixElectricFencedMemory.Free(p); } else { Win32ElectricFencedMemory.Free(p); } }