Why is fread sometimes taking so long?

This is a discussion on Why is fread sometimes taking so long? within the C++ Programming forums, part of the General Programming Boards category; Ok... I'm writting an application that loads bitmap data from a file and shows it at a specified speed... Ok, ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    55

    Why is fread sometimes taking so long?

    Ok... I'm writting an application that loads bitmap data from a file and shows it at a specified speed... Ok, I'm having a problem with the speed of fread. At the beginning of the application, I open the file, get some info from the header and then start doing fread of each bitmap and showing it. However, these are the speeds I'm getting with each fread (in miliseconds):

    80-27-3-78-93-3-252-194-4-4-5-76-4-80-94-5-227-223-4-3-4-78-3-180-518-3-3-25-238-229
    -4-3-3-102-4-212-202-4-4


    I should be getting 3~5ms of each fread, but I'm getting really slow fread lots of times... Before using fread, I was testing my application by doing a LoadBitmap and then doing a two GetDIBits to get the bmp data (exactly what my file contains now)... Doing that, I was achieving a stable 27 frames per second... As you can see, now I'm getting really poor FPSs and really unstable too... Damn, please tell me you know how to fix it...

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    1. Profiling - to be sure that the problem is fread and not some memory management that happends around
    2. Caching (read big chunks and then process them from the memory, not from disk)
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Sounds like some other process/program is doing a bunch of disk IO and hosing up your game.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. long int type
    By sarahr202 in forum C++ Programming
    Replies: 4
    Last Post: 05-20-2009, 12:55 PM
  2. Dev-cpp - compiler options
    By tretton in forum C Programming
    Replies: 7
    Last Post: 01-06-2006, 05:20 PM
  3. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 07:55 AM
  4. rehash help
    By kashifk in forum C++ Programming
    Replies: 1
    Last Post: 10-22-2003, 06:51 PM
  5. Please help me
    By teedee46 in forum C++ Programming
    Replies: 9
    Last Post: 05-06-2002, 11:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21