Answered by:
Efficient way of reading binary file into byte array?

Question
-
What is the most efficient (fastest) way to read a binary file into a byte array?Thursday, February 11, 2010 2:29 PM
Answers
-
- Marked as answer by BBauer42 Thursday, February 11, 2010 4:15 PM
Thursday, February 11, 2010 3:10 PM
All replies
-
File.ReadAllBytes?
- Proposed as answer by Louis.fr Thursday, February 11, 2010 3:51 PM
Thursday, February 11, 2010 2:34 PM -
- Marked as answer by BBauer42 Thursday, February 11, 2010 4:15 PM
Thursday, February 11, 2010 3:10 PM -
Since you want it in a byte array File.ReadAllbytes as proposed by Tergiver would be better then FileStream.Read since that would require you to write/maintain some extra code to open/close the file.Thursday, February 11, 2010 4:23 PM
-
Memory mapping a file is the most I/O efficient way. .NET 4.0 will
include support for this. There is also a wrapper for the Win32 Memory
Mapped File services which can be used with other versions of .NET,
http://github.com/tomasr/filemap/
Keep in mind memory mapping isn't always the best solution. See
http://en.wikipedia.org/wiki/Memory-mapped_file#DrawbacksThursday, February 11, 2010 5:25 PM