/* Do not prepopulate * public void Setup(int smallCount, int largeCount) { lock (smallPool) { this.smallCount = smallCount; for (int i = 0; i < smallCount; i++) { MemoryBuffer a = new MemoryBuffer(SmallBuffer); smallPool.Push(a); } } lock (pool) { this.largeCount = largeCount; for (int i = 0; i < largeCount; i++) { MemoryBuffer a = new MemoryBuffer(Buffer); pool.Push(a); } } }*/ public MemoryBuffer GetBuffer() { lock (pool) { if (pool.Count > 0) return pool.Pop(); } var a = new MemoryBuffer(Buffer); return a; }
public MemoryBuffer GetSmallBuffer() { lock (smallPool) { if (smallPool.Count > 0) return smallPool.Pop(); } var a = new MemoryBuffer(SmallBuffer); return a; }
public void ReceiveData(MemoryBuffer buff) { buffers.Add(buff); }
public void FreeBuffer(MemoryBuffer input) { input.SetDataLocation(0, 0); if (input.Data.Length == SmallBuffer) { lock (smallPool) smallPool.Push(input); } else if (input.Data.Length == Buffer) { lock (pool) pool.Push(input); } else { logger.Warn("Tried to free incorrectly sized arg with length: {0}", input.Data.Length); } }