cutom stream

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am planning to implement custom stream which will be memory stram until
certain point and then become file stream if it exceed cetain size any ideas
would be very helpful
 
I am planning to implement custom stream which will be memory stram until
certain point and then become file stream if it exceed cetain size any
ideas would be very helpful

I would simply inherit Stream and implement the required methods,
including a field that holds a reference to an internal Stream to which
you forward those methods, which is set to a MemoryStream until some point
in time that you decide (for example, the MemoryStream becomes too large),
at which point you copy the MemoryStream to a new FileStream, and then
replace your internal Stream reference with the new FileStream.

That said, you should think carefully as to whether you really want to do
this. If you have a specific design requirement that the data wind up on
the disk in a file accessible to the user once it gets too large, then
perhaps your goal makes sense. But if you are simply trying to do some
sort of caching or something, in a way hidden to the user, you are likely
to perform _worse_ trying to implement it yourself rather than just
letting the Windows memory manager deal with it for you.

In other words, just use a MemoryStream, and let Windows decide what is
"too large" as well as let Windows copy your data to the disk as necessary
(via the normal virtual memory management strategies).

Pete
 
Back
Top