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 Put(T value) { value.IsPooled = true; int index = value.Index; if (index >= 0) { value.SetDefaultValue(); array[index].Value = value; full.Push(index); } else { value.Dispose(); } }
private bool GetAllocated(int size, out int index, out int offset) { int itemIndex = ready[GetBitOffset(size)].Pop(); if (itemIndex >= 0) { index = (int)(array[itemIndex].Value >> 32); offset = (int)array[itemIndex].Value; empty.Push(itemIndex); return(true); } else { index = -1; offset = -1; return(false); } }
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 } }
public T Get() { T result = default(T); int index = full.Pop(); if (index >= 0) { result = array[index].Value; array[index].Value = default(T); empty.Push(index); } else { result = new T(); result.SetDefaultValue(); Interlocked.Increment(ref created); } result.IsPooled = false; return(result); }