Thread: efficient binary file read

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    1) Have one short int.
    2) Have one float array.
    3) Have a loop where a short int is read, converted to a float and placed inside the float array.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    In fact, 3 should be a simple assignment. Just store it directly into the float array.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    17
    Thanks for the replies

    But these files are big. Reading an int at a time and making the assignment to the elements of a float array will take a lot more time than using fread to read the big block of data. Wont it?

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Are you allowed to rewrite the file? Cause if reading it that way is a problem, then you should store floating point numbers in the file as well. Then you can just read them into memory at once.

    If not, then what MacGyver suggested is as good as it's going to get it seems.

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Marv View Post
    Thanks for the replies

    But these files are big. Reading an int at a time and making the assignment to the elements of a float array will take a lot more time than using fread to read the big block of data. Wont it?
    Nope.

    EDIT: Yikes. I'm contributing to the resurrection of a defunct thread. Let's just let this one die, eh?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Read and write binary file?
    By Loic in forum C++ Programming
    Replies: 2
    Last Post: 10-29-2008, 05:31 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM