tags:

views:

58

answers:

1

Is there a class which, rather than copying data written to it into an internal array which is occasionally resized (as MemoryStream does), retains a reference to each buffer that users pass into it on write, and maintains a data structure which keeps track of each buffer written and the offset/count? It should also support a read mechanism which will provide clients with a buffer, offset, and count (rather than requiring clients to allocate and provide a buffer into which the data is copied for each read).

Essentially I need something which retains data by reference and doesn't do any significant allocations or any data copying behind my back. For some reason I doubt the BCL provides this. Any known implementations?

+1  A: 

Would a

List<ArraySegment<byte>>

do?

dtb
That's handy; I didn't know about the ArraySegment struct. It's not a full implementation of what I want, but definitely a step in the right direction.
bvanderveen
ArraySegment<> doesn't store anything.
Hans Passant
The more I think about it, I'm not sure that what I asked for is exactly what I want. But whatever it is that I end up with, it will involve ArraySegment. Thanks.
bvanderveen