c# - File I/O with streams - best memory buffer size -


I am writing a small I / O library to assist with a big (hobby) project. A part of this library performs different functions on a file, which is read through the FileStream object. On each streamReader. Read (...) ,

I prevent an event that will be used in the main app to display progress information. The loop processing is wired, but not very time consuming (this can be just a simple file copy, for example, or encryption may include ...).

My main question is: What is the best memory buffer size to use? Thinking about the physical disk layout, I could choose 2K, which would cover a CD sector size and 512 bytes would be a lot of hard disk sector. High above Abstract Tree, you can go for a bigger buffer which can read an entire FAT cluster at a time. I feel with today's PC, I can go for a more hungry hunger option (for example, a couple of MIBs), but then I increase time between UI updates and the user considers less sensitive applications.

On the one hand, I am hoping to provide interface similar to the files hosting the FTP / HTTP server (on local network / Fast DSL). What would be the best memory buffer size for those people (again, a "best-case" control between perceived accountability versus performance)?

The files are already buffering by the file system cache. You just need to take a buffer size, which does not force the file stream to fill the original Windows Readfile (API) call buffer. Do not go below one kilobyte, there is a waste of memory more than 16Kb and memory wastage for CPU (usually 16 or 32 & nbsp; KB of data).

4 & nbsp; KB is a traditional choice, even if only a virtual memory page will actually be caused by accident. Profile is difficult; How much time you take to read a cached file will end the measurement of data available in the cache, which runs at 5 gigabytes / second, speed of RAM. The second time you run your test, it will be in the cache, and this will not often happen in the environment of production. File I / O is fully defined by disk drive and it is slow to glaciely, copying data is peanuts 4 & nbsp; KB will work fine.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -