Пример #1
0
            public unsafe void Return(ref RawBuffer buffer)
            {
#if DEBUG
                //There are a lot of ways to screw this up. Try to catch as many as possible!
                var blockIndex            = buffer.Id >> SuballocationsPerBlockShift;
                var indexInAllocatorBlock = buffer.Id & SuballocationsPerBlockMask;
                Debug.Assert(outstandingIds.Remove(buffer.Id),
                             "This buffer id must have been taken from the pool previously.");
#if LEAKDEBUG
                bool found = false;
                foreach (var pair in outstandingAllocators)
                {
                    if (pair.Value.Remove(buffer.Id))
                    {
                        found = true;
                        if (pair.Value.Count == 0)
                        {
                            outstandingAllocators.Remove(pair.Key);
                            break;
                        }
                    }
                }
                Debug.Assert(found, "Allocator set must contain the buffer id.");
#endif
                Debug.Assert(buffer.Length == SuballocationSize,
                             "A buffer taken from a pool should have a specific size.");
                Debug.Assert(blockIndex >= 0 && blockIndex < BlockCount,
                             "The block pointed to by a returned buffer should actually exist within the pool.");
                var memoryOffset = buffer.Memory - Blocks[blockIndex].Pointer;
                Debug.Assert(memoryOffset >= 0 && memoryOffset < Blocks[blockIndex].Array.Length,
                             "If a raw buffer points to a given block as its source, the address should be within the block's memory region.");
                Debug.Assert(Blocks[blockIndex].Pointer + indexInAllocatorBlock * SuballocationSize == buffer.Memory,
                             "The implied address of a buffer in its block should match its actual address.");
                Debug.Assert(buffer.Length + indexInAllocatorBlock * SuballocationSize <= Blocks[blockIndex].Array.Length,
                             "The extent of the buffer should fit within the block.");
#endif
                Slots.Return(buffer.Id, new PassthroughArrayPool <int>());
            }
Пример #2
0
            public unsafe void Return(int slotIndex)
            {
#if DEBUG
                Debug.Assert(outstandingIds.Remove(slotIndex),
                             "This buffer id must have been taken from the pool previously.");
#if LEAKDEBUG
                bool found = false;
                foreach (var pair in outstandingAllocators)
                {
                    if (pair.Value.Remove(slotIndex))
                    {
                        found = true;
                        if (pair.Value.Count == 0)
                        {
                            outstandingAllocators.Remove(pair.Key);
                            break;
                        }
                    }
                }
                Debug.Assert(found, "Allocator set must contain the buffer id.");
#endif
#endif
                Slots.Return(slotIndex, new PassthroughArrayPool <int>());
            }