using System; namespace MLAPI.Serialization.Pooled { /// /// Disposable NetworkBuffer that returns back to the NetworkBufferPool when disposed /// public sealed class PooledNetworkBuffer : NetworkBuffer, IDisposable { private bool isDisposed = false; internal PooledNetworkBuffer() { } /// /// Gets a PooledNetworkBuffer from the static NetworkBufferPool /// /// PooledNetworkBuffer public static PooledNetworkBuffer Get() { var buffer = NetworkBufferPool.GetBuffer(); buffer.isDisposed = false; return buffer; } /// /// Returns the PooledNetworkBuffer into the static NetworkBufferPool /// public new void Dispose() { if (!isDisposed) { isDisposed = true; NetworkBufferPool.PutBackInPool(this); } } } }