Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8837461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:43:49+00:00 2026-06-14T09:43:49+00:00

Much like the same functionality in HxD editor, I am implementing a program that

  • 0

Much like the same functionality in HxD editor, I am implementing a program that searches for a specific hex-value (say 32 bits) in a big binary files (> 1 GB). Memory is limited and it seems that reading chunk by chunk is quite slow with BinaryReader class. HxD returns the search result (reaching almost the end of the file) in about 12 seconds which is acceptable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:43:51+00:00Added an answer on June 14, 2026 at 9:43 am

    BinaryReader should be able to read a gigabyte in 12 seconds, provided your disk subsystem can handle it (which it apparently can, since HxD is doing it). The key is opening the file with a larger input buffer. That is, rather than:

    var f = File.OpenRead(filename)
    

    Call

    var f = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None, 65536);
    

    That will cause .NET to read the file in 64 KB chunks rather than the default 4 KB chunks.

    Although why you’re using BinaryReader at all is something of a mystery. Why not read the stream directly? For example:

    var buff = new byte[1024*1024];
    int bytesRead = f.Read(buff, 0, buff.Length);
    

    With a 64 KB file buffer, .NET has to make only 16 calls to the OS to fulfill your request. Using the default 4K buffer, it would have to make 256 calls to the OS. The difference is remarkable.

    Using a buffer size argument larger than 64 kilobytes doesn’t give you much in the way of performance improvement. And a buffer larger than 256 KB actually caused the system to read slower in my tests. 64 KB seems to be the “sweet spot,” at least on the systems I tested with.

    If you decide to use BinaryReader for some reason, you should expect a similar performance increase with the larger buffer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Much like the Stackoverlow reputation rounding, I'm hoping to do the same thing with
I've implemented a webservice authentication which works pretty much the same like amazon s3.
My question is very much like Getting the return value of a PL/SQL function
Is there a library much like how openssl is imported into C programs that
I have a PHP script that very much like a commenting system, but requires
I'm coding an app that works much like Apple's Weather.app: There's a UIPageControl at
I am learning CouchDB I and like its functionality very much. One things bugs
We've got an android app and an iPhone app (same functionality) that use sqlite
Is it possible to get the same Test List Editor functionality from Visual Studio
I don't know how much I can say about the app that I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.