Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Getting speed in file reading

Getting speed in file reading

Scheduled Pinned Locked Moved C / C++ / MFC
c++performancehelpquestiondiscussion
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nadiric
    wrote on last edited by
    #1

    I'm looking to maximize my speed while reading a binary file - the file contains a mix of floats & ints(4bytes each) and occasional strings. Floats and ints are converted to the correct endianess post read using bit shifts and masks. I've fine tuned everything I can think of for reading the file, but have not previously considered changing the interface to the file. I am currently using FILE * with the associated fread, seek etc. functions for no better reason than this being what my original C code used (this entire app is now ported to VC++ with MFC). Is there a faster file reader I should consider? Any speed increase would help, as I am reading 100's of megs of data. Thanks for any opinions.

    A M S W 4 Replies Last reply
    0
    • N nadiric

      I'm looking to maximize my speed while reading a binary file - the file contains a mix of floats & ints(4bytes each) and occasional strings. Floats and ints are converted to the correct endianess post read using bit shifts and masks. I've fine tuned everything I can think of for reading the file, but have not previously considered changing the interface to the file. I am currently using FILE * with the associated fread, seek etc. functions for no better reason than this being what my original C code used (this entire app is now ported to VC++ with MFC). Is there a faster file reader I should consider? Any speed increase would help, as I am reading 100's of megs of data. Thanks for any opinions.

      A Offline
      A Offline
      aks
      wrote on last edited by
      #2

      try CreateFile() API Please chk http://msdn2.microsoft.com/en-US/library/aa363858.aspx

      AJay

      1 Reply Last reply
      0
      • N nadiric

        I'm looking to maximize my speed while reading a binary file - the file contains a mix of floats & ints(4bytes each) and occasional strings. Floats and ints are converted to the correct endianess post read using bit shifts and masks. I've fine tuned everything I can think of for reading the file, but have not previously considered changing the interface to the file. I am currently using FILE * with the associated fread, seek etc. functions for no better reason than this being what my original C code used (this entire app is now ported to VC++ with MFC). Is there a faster file reader I should consider? Any speed increase would help, as I am reading 100's of megs of data. Thanks for any opinions.

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        As Ajaywinds mentioned, you can get rid of a bit of overhead by using the Windows file APIs directly, instead of through the ANSI CRT functions.  If you must remain ANSI C compliant this isn't an option. I would think anything you can do in RAM will help much more.  Buffer as much as you can into RAM before parsing, especially if everything you read will be parsed. Seeking is costly.  If you have to jump all over the place in the file to parse it then performance will suffer.  Design file layout for serial access if possible. If you can use file I/O APIs, and the format of the files allows it, consider using overlapped I/O. You can be parsing data in RAM while data is being read from disk. Just my 2 cents, Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        1 Reply Last reply
        0
        • N nadiric

          I'm looking to maximize my speed while reading a binary file - the file contains a mix of floats & ints(4bytes each) and occasional strings. Floats and ints are converted to the correct endianess post read using bit shifts and masks. I've fine tuned everything I can think of for reading the file, but have not previously considered changing the interface to the file. I am currently using FILE * with the associated fread, seek etc. functions for no better reason than this being what my original C code used (this entire app is now ported to VC++ with MFC). Is there a faster file reader I should consider? Any speed increase would help, as I am reading 100's of megs of data. Thanks for any opinions.

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          Perhaps try using memory mapped files. See here[^] for details.

          Steve

          N 1 Reply Last reply
          0
          • N nadiric

            I'm looking to maximize my speed while reading a binary file - the file contains a mix of floats & ints(4bytes each) and occasional strings. Floats and ints are converted to the correct endianess post read using bit shifts and masks. I've fine tuned everything I can think of for reading the file, but have not previously considered changing the interface to the file. I am currently using FILE * with the associated fread, seek etc. functions for no better reason than this being what my original C code used (this entire app is now ported to VC++ with MFC). Is there a faster file reader I should consider? Any speed increase would help, as I am reading 100's of megs of data. Thanks for any opinions.

            W Offline
            W Offline
            Waldermort
            wrote on last edited by
            #5

            Try mapping the file to memory. Also if you know the exact layout of the file you could define a struct and cast the pointer directly.

            1 Reply Last reply
            0
            • S Stephen Hewitt

              Perhaps try using memory mapped files. See here[^] for details.

              Steve

              N Offline
              N Offline
              nadiric
              wrote on last edited by
              #6

              This sounds most promising...

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups