示例#1
0
        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);
        }
示例#2
0
        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);
            }
        }