Пример #1
0
        public void ReclaimedBlockShouldReinitializeToDefault()
        {
            using var memory = new HeapAllocator(_logFactory);


            var handle_50331651_48 = Take(memory, 9150);

            memory.Validate("1");

            memory.Free(ref handle_50331651_48);
            memory.Validate("2");

            var handle_16777217_18 = Take(memory, 33831);

            memory.Validate("3");

            memory.Free(ref handle_16777217_18);
            memory.Validate("4");

            var handle_67108866_64 = Take(memory, 22);

            memory.Validate("5");

            memory.Free(ref handle_67108866_64);
            memory.Validate("6");
        }
 private void CheckCapacity()
 {
     if (_queues[0].Count <= 5)
     {
         // -------- Multiply by 2 the capacity
         LinkedIndexPoolEntry *olds = _entries;
         int newCapacity            = _capacity * 2;
         _entries = (LinkedIndexPoolEntry *)HeapAllocator.New(sizeof(LinkedIndexPoolEntry) * newCapacity);
         MemoryHelper.Copy((byte *)olds, (byte *)_entries, sizeof(LinkedIndexPoolEntry) * _capacity);
         for (int i = _capacity; i < newCapacity; i++)
         {
             _entries[i].Previous = i - 1;
             _entries[i].Next     = i + 1;
             _entries[i].Index    = i;
             _entries[i].Queue    = 0;
         }
         _entries[newCapacity - 1].Next = -1;
         // -------- Fix 0 queue :
         _entries[_queues[0].Last].Next = _capacity;
         _entries[_capacity].Previous   = _queues[0].Last;
         _queues[0].Last   = newCapacity - 1;
         _queues[0].Count += _capacity;
         // --------
         _capacity = newCapacity;
         HeapAllocator.Free((byte *)olds);
         CheckCoherency();
     }
 }
 public void Release()
 {
     if (_entries != null)
     {
         HeapAllocator.Free((byte *)_entries);
         _entries = null;
     }
 }
 public void Release()
 {
     if (_capacity > 0)
     {
         HeapAllocator.Free((byte *)_entries);
         HeapAllocator.Free((byte *)_queues);
         _queueStack.Release();
         _capacity = -1;
     }
 }
 private void EnsureCpacity(int n)
 {
     if (n >= _capacity)
     {
         int  newCapacity = _capacity * 2;
         int *newEntries  = (int *)HeapAllocator.New(newCapacity * sizeof(int));
         MemoryHelper.Copy((byte *)_entries, (byte *)newEntries, _capacity * sizeof(int));
         HeapAllocator.Free((byte *)_entries);
         for (int i = _capacity; i < newCapacity; i++)
         {
             newEntries[i] = i + _idOffset;
         }
         _entries  = newEntries;
         _capacity = newCapacity;
     }
 }
Пример #6
0
        public void OrphanBlockWithSizeZeroShouldReclaim()
        {
            using var memory = new HeapAllocator(_logFactory);

            var handle0 = memory.Take(24);
            //memory.Validate();

            var handle1 = memory.Take(24);
            //memory.Validate();

            var handle2 = memory.Take(24);
            //memory.Validate();

            var handle4 = memory.Take(24);

            //memory.Validate();

            memory.Free(ref handle1);
            //memory.Validate();

            memory.Free(ref handle0);
            //memory.Validate();

            var handle5 = memory.Take(24);
            //memory.Validate();
            var handle6 = memory.Take(24);

            //memory.Validate();

            memory.Free(ref handle4);
            //memory.Validate();

            memory.Free(ref handle2);
            //memory.Validate();

            memory.Free(ref handle6);
            //memory.Validate();

            memory.Free(ref handle5);
            //memory.Validate();
        }