public void Dispose() { for (; ;) { int index = full.Pop(); if (index < 0) { break; } array[index].Value.Dispose(); array[index].Value = default(T); } }
public bool Recycle(Socket socket, AddressFamily family) { if (isEnabled) { int index = empty.Pop(); if (index >= 0) { array[index].Value = socket; GetFull(family).Push(index); return(true); } } return(false); }
public void Dispose() { if (isEnabled) { isEnabled = false; int index; while ((index = full4.Pop()) >= 0) { array[index].Value.Close(); empty.Push(index); } while ((index = full6.Pop()) >= 0) { array[index].Value.Close(); empty.Push(index); } } }
public void Free(ArraySegment <byte> segment) { int bufferIndex = 0; while (bufferIndex < buffers.Length && buffers[bufferIndex] != segment.Array) { bufferIndex++; } if (bufferIndex >= buffers.Length) { throw new ArgumentException("SmartBufferPool.Free, segment.Array is invalid"); } int index = empty.Pop(); array[index].Value = ((long)bufferIndex << 32) + segment.Offset; ready[GetBitOffset(segment.Count)].Push(index); }
public void Put(T value) { value.IsPooled = true; int index = empty.Pop(); if (index >= 0) { value.SetDefaultValue(); array[index].Value = value; full.Push(index); } else { value.Dispose(); #if DEBUG throw new Exception(@"BufferPool too small"); #endif } }