[Mono-dev] Should we replace MemoryStream?
steveb at mindtouch.com
Tue Nov 10 13:15:49 EST 2009
I have an updated ChunkedMemoryStream implementation that mimics
MemoryStream behavior up to the default chunk size, at which point it
starts to use chunks. GetBuffer() consolidates all chunks into the
main buffer, which means that any direct changes would be reflected.
Where can I find the mono unit tests for MemoryStream? That will save
me some time from having to write my own. At that point, I would
encourage everyone to look at it and try it out with real world data.
Steve G. Bjorg
On Nov 10, 2009, at 9:56 AM, Avery Pennarun wrote:
> On Tue, Nov 10, 2009 at 12:42 PM, Robert Jordan <robertj at gmx.net>
>> An algorithm based on a MemoryStream implemented with chunks will
>> perform better in average. I fully agree with that.
>> The problem is that one method (GetBuffer) *will be* unexpected
> I just don't believe this is true. I think we're moving the slowness
> from "add to buffer" into GetBuffer(). However, it is not
> *additional* slowness. It is simply displaced slowness, and it's
> potentially *less* slowness overall.
> I'm not sure I can imagine a program that would be negatively affected
> by this. Doesn't the gc cause random slowness sometimes anyway?
>> and another one, much harder to fix: it is allowed to change
>> the buffer even before the stream has been closed. This means that
>> after every GetBuffer call, the implementation must behave
>> because it must somehow deal with a changed underlying buffer.
> I don't think this is a problem either. Since you're now using the
> returned buffer as your one-and-only chunk, you can use it just as you
> always would. If someone then pushes so much new data into the stream
> that you would exceed the buffer size, you would have to do what you
> would do in the non-chunked implementation; either a) reject it, or b)
> not guarantee that it ends up in the array from the earlier
> GetBuffer(). I'm not sure which is the correct behaviour, but both
> are easily implemented in the chunked implementation too, particularly
> since it has to support user-supplied fixed-length buffers anyhow.
> Perhaps I'm missing something...
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
More information about the Mono-devel-list