public void ReuseInstanceTest() { StreamManagerPool l_StreamManagerPool = CreatePool(); MemoryBlock l_Block = l_StreamManagerPool.GetBlock(); l_Block.ReturnBlock(); MemoryBlock l_Block2 = l_StreamManagerPool.GetBlock(); Assert.Equal(l_Block, l_Block2); }
protected internal virtual List <MemoryBlock> GetBlock(long p_Capacity, long p_TargetCapacity) { List <MemoryBlock> l_Blocks = new List <MemoryBlock>(); long l_NeededBytes = p_TargetCapacity - p_Capacity; while (l_NeededBytes > 0) { // Find Best Pool StreamManagerPool l_Pool = m_ChooserPolicy.FindBestPool(p_Capacity, p_TargetCapacity); if (l_Pool == null) { throw new Exception($"No Pool found. Capacity {p_Capacity}, TargetCapacity {p_TargetCapacity}, Remaining Bytes {l_NeededBytes}"); } // Allocated all necessary blocks while (l_NeededBytes > 0) { // If if max usage reached restart and search for a different pool if (!m_ChooserPolicy.PoolHasFreeBlocks(l_Pool)) { break; } MemoryBlock l_MemoryBlock = l_Pool.GetBlock(); l_NeededBytes = l_NeededBytes - l_MemoryBlock.GetLength(); l_Blocks.Add(l_MemoryBlock); } } return(l_Blocks); }
public void GetAndReturnTest() { StreamManagerPool l_Pool = CreatePool(); Assert.Equal(0, l_Pool.GetBlocksInUse()); Assert.True(l_Pool.HasFreeBlocks()); MemoryBlock l_Block = l_Pool.GetBlock(); Assert.NotNull(l_Block); Assert.Equal(1, l_Pool.GetBlocksInUse()); l_Block.ReturnBlock(); Assert.Equal(0, l_Pool.GetBlocksInUse()); }