Ejemplo n.º 1
0
        internal static HeapMemory Alloc(uint size)
        {
            uint allocSize = Math.Max(minBufferSize, CalculateMultiple(size, bufferMultiple));

            if (_pooledMemory.Count == 0)
            {
                _createdPools++;

                if (_createdPools >= 1024 && !_hasWarnedAboutLeak)
                {
                    Console.WriteLine("Memory leak detected. Are you leaking memory to the GC or are your windows too large? Leaking memory to the GC will cause slowdowns. Make sure all memory is deallocated.");
                    _hasWarnedAboutLeak = true;
                }

                return(new HeapMemory(allocSize));
            }

            HeapMemory memory = _pooledMemory.Dequeue();

            memory.EnsureSize(allocSize);

            memory.isDead        = false;
            memory.VirtualCount  = allocSize;
            memory.VirtualOffset = 0;

            return(memory);
        }