The BlockAllocatedMemoryStream has two primary benefits over a normal MemoryStream, first, the allocation of a large contiguous array of data in MemoryStream can fail when the requested amount of contiguous memory is unavailable - the BlockAllocatedMemoryStream prevents this; second, a MemoryStream will constantly reallocate the buffer size as the stream grows and shrinks and then copy all the data from the old buffer to the new - the BlockAllocatedMemoryStream maintains its blocks over its life cycle, unless manually cleared, thus eliminating unnecessary allocations and garbage collections when growing and reusing a stream.
Important: Unlike MemoryStream, the BlockAllocatedMemoryStream will not use a user provided buffer as its backing buffer. Any user provided buffers used to instantiate the class will be copied into internally managed reusable memory buffers. Subsequently, the BlockAllocatedMemoryStream does not support the notion of a non-expandable stream. If you are using a MemoryStream with your own buffer, the BlockAllocatedMemoryStream will not provide any immediate benefit.
Note that the BlockAllocatedMemoryStream will maintain all allocated blocks for stream use until the Clear method is called or the class is disposed.
No members in the BlockAllocatedMemoryStream are guaranteed to be thread safe. Make sure any calls are synchronized when simultaneously accessed from different threads.