C# (CSharp) ServiceStack.Text RecyclableMemoryStream - 1 exemples trouvés. Ce sont les exemples réels les mieux notés de ServiceStack.Text.RecyclableMemoryStream extraits de projets open source. Vous pouvez noter les exemples pour nous aider à en améliorer la qualité.
MemoryStream implementation that deals with pooling and managing memory streams which use potentially large buffers.
This class works in tandem with the RecylableMemoryStreamManager to supply MemoryStream objects to callers, while avoiding these specific problems: 1. LOH allocations - since all large buffers are pooled, they will never incur a Gen2 GC 2. Memory waste - A standard memory stream doubles its size when it runs out of room. This leads to continual memory growth as each stream approaches the maximum allowed size. 3. Memory copying - Each time a MemoryStream grows, all the bytes are copied into new buffers. This implementation only copies the bytes when GetBuffer is called. 4. Memory fragmentation - By using homogenous buffer sizes, it ensures that blocks of memory can be easily reused. The stream is implemented on top of a series of uniformly-sized blocks. As the stream's length grows, additional blocks are retrieved from the memory manager. It is these blocks that are pooled, not the stream object itself. The biggest wrinkle in this implementation is when GetBuffer() is called. This requires a single contiguous buffer. If only a single block is in use, then that block is returned. If multiple blocks are in use, we retrieve a larger buffer from the memory manager. These large buffers are also pooled, split by size--they are multiples of a chunk size (1 MB by default). Once a large buffer is assigned to the stream the blocks are NEVER again used for this stream. All operations take place on the large buffer. The large buffer can be replaced by a larger buffer from the pool as needed. All blocks and large buffers are maintained in the stream until the stream is disposed (unless AggressiveBufferReturn is enabled in the stream manager).