rlrcstr <rl*****@discussions.microsoft.comwrote:
Is it possible to truncate a MemroyStream to free up the space up to the
current position?
I wantes to be able to just keep dumping bytes into a stream and then read
the stream as needed. After the read, free up the portion of the stream I
read, esentially making the first unread byte the first byte in the stream.
MemoryStreams are basically backed by a byte array. You'd need to make
a copy of the part of the byte array you still need, and either create
a new MemoryStream or reset the current one. Your Position property is
likely to be wrong afterwards though...
It would possibly be easier to write such a stream class yourself than
to use MemoryStream. For one thing, you could make it use several
chunks of memory rather than a single byte array, which would make it
cheaper to throw the start away.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too