开发者_运维技巧We are reading huge files in to memorystream and reusing them across mulitple locations in the code. Just wondering if it is a better idea to get byte[] of files and store them in a hashtable for such a scenario. This way we could close the memorystream when we are done and just recreate one from hashtable when needed. Just wondering if there are any drawbacks with this method. Thanks N
One advantage of using a byte[]
rather than a MemoryStream
is that the MemoryStream
has more state - it has a cursor. In particular, two threads could easily read from the same byte array (copying the section they're interested in etc) whereas if they tried to use Stream.Read
concurrently, they may not get the expected results.
The downside of both of these is that they're mutable :(
Just wondering if there are any drawbacks with this method.
For huge files? How large is “huge”? How much main memory can you use?
If the files are really that big, then you're better off not keeping them in memory in the first place. Instead you should be reading them as and when they're needed, in order to reduce memory usage.
精彩评论