Operation of MemoryTributary

MemoryTributary works by maintaining a list of byte[], which store the data of the stream. The Read() and Write() methods split up the data, copying it in chunks to and from these arrays or 'blocks'. The block, and offset into the block, for the current Position at any given time are accessed via a set of properties which all the Stream methods operate on.

Blocks are allocated on demand as soon as they are accessed for a read or write via the property, and are allocated in sequence, so the list is always 'solid'.

The Length member maintains a record of how much data has been written to the stream, to prevent reading from uninitialised memory. This can be overridden with the SetLength() method.

Optimising MemoryTributary - Block Size

The block size (the size of each byte[] in the list) is controlled by the blockSize member. The optimum size depends on the application. Too small and MemoryTributary will have to allocate, and split the data so often its efficiency gains will be gone; too large and it risks suffering the same problems as MemoryStream (though it would need to be very large for this!). The default size is 64KB.

Last edited Mar 22, 2012 at 10:30 AM by sebastianfriston, version 3


No comments yet.