// private static methods private static byte[] GetChunkBytes(BsonChunk chunk) { if (chunk == null) { throw new ArgumentNullException("chunk"); } return(chunk.Bytes); }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (!Disposed) { if (disposing) { if (_chunk != null) { _chunk.DecrementReferenceCount(); _chunk = null; } } } base.Dispose(disposing); }
/// <summary> /// Releases a chunk. /// </summary> /// <param name="chunk">The chunk.</param> internal void ReleaseChunk(BsonChunk chunk) { if (chunk.ReferenceCount != 0) { new BsonInternalException("A chunk is being returned to the pool and the reference count is not zero."); } lock (_lock) { if (_chunks.Count < _maxPoolSize) { _chunks.Push(chunk); } // otherwise just let it get garbage collected } }
// private static methods private static byte[] GetChunkBytes(BsonChunk chunk) { if (chunk == null) { throw new ArgumentNullException("chunk"); } return chunk.Bytes; }
// constructors /// <summary> /// Initializes a new instance of the <see cref="SingleChunkBuffer"/> class. /// </summary> /// <param name="chunk">The chunk.</param> /// <param name="sliceOffset">The slice offset.</param> /// <param name="length">The length.</param> /// <param name="isReadOnly">Whether the buffer is read only.</param> public SingleChunkBuffer(BsonChunk chunk, int sliceOffset, int length, bool isReadOnly) : base(GetChunkBytes(chunk), sliceOffset, length, isReadOnly) { _chunk = chunk; chunk.IncrementReferenceCount(); }