问题描述
什么是在应用方面BufferedStream和MemoryStream的区别?
由于MemoryStream的可以在任何时候被冲刷成一个文件,不能取代它BufferedStream?
What is the difference between BufferedStream and MemoryStream in terms of application?Since MemoryStream can be flushed into a file at any time, couldn't it replace BufferedStream?
推荐答案
BufferedStream
只是一个缓冲在现有流。 是一个缓冲区为的全的流 - 它没有链接到另外一个。你可以要求它自己写随时另一个流,但是这不是一回事。
BufferedStream
is just a buffer over an existing stream. MemoryStream
is a buffer for the whole stream - it isn't chained to another one. You can ask it to write itself to another stream at any time, but that's not the same thing.
一个原则原因缓冲,以避免频繁的写入昂贵资源。但是,这并不意味着要缓冲的所有的内存中的数据 - 就足以避免非常小的写操作。例如,如果的FileStream
没有它的的的缓冲策略,然后包装它 BufferedStream
最终可能与一个只有8K的缓冲区,即使你写兆字节的数据。正如在评论中指出,虽然,。
One of the principle reasons for buffering is to avoid frequent writes to expensive resources. However, that doesn't mean you want to buffer all the data in memory - just enough to avoid very small writes. For example, if FileStream
didn't have its own buffering strategy, then wrapping it in BufferedStream
could end up with a buffer of only 8K even if you write megabytes of data. As pointed out in the comments though, FileStream
has enough buffering that using BufferedStream
in conjunction with it is pointless.
这篇关于是什么在应用方面BufferedStream和MemoryStream的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!