Thread: fread item_size limit

  1. #1
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany

    fread item_size limit

    I'm using the function fread to read binary data from files.

    According to the MSDN, fread has the following parameters:

    size_t fread( void *buffer, size_t size, size_t count, FILE *stream


    Storage location for data.

    Item size in bytes.

    Maximum number of items to be read.

    Pointer to FILE structure.

    When I read data from a local drive all is fine. Whenever I read data from a network path ( even my own drive shared and mapped as network path ) my item size may not be more than 64MB. If it's 64MB+1 Byte, fread fails. As I know this now, I can simply read more items, because I end up with itemsize*count bytes anyway, but I'm curious. Why is this ? Does anyone know why there is a 64MB limit ? There was no mention in the documentation...

    BTW: System is XP and 2000 both having these problems.

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  2. #2
    Registered User Mortissus's Avatar
    Join Date
    Dec 2004
    Brazil, Porto Alegre
    I am not sure, never had this kind of problem. But, from past experiences with sockets, I know that, dependening on the protocol used, you must transmit/read information in chunks. For example, Ethernet, there is a MTU (which I don´t know, sorry), if you want to send more than MTU, the send function does not fail, but does not send all data. You should manually read/send remaining chunks. Something like this:
    char* my_read(int bytes_to_read, FILE* file){
       int count = 0;
       char* bytes = new char(bytes_to_read);
       while(count < bytes_to_read){
          count = fread(&bytes[count], 1, bytes_to_read-count, file);
       return bytes;
    If the function really fails and does not return anything, you could do:
    while(count  < bytes_to_read){
       //read 1 mb at a time
       count = fread(&bytes[count], 1, 1024, file);
    Note: I haven´t compiled this code, in any case, it is just a pseudo-code

    Hope that helps!

  3. #3
    Registered User Mortissus's Avatar
    Join Date
    Dec 2004
    Brazil, Porto Alegre
    2 ^16 = 65536
    64mb = 65536 KB

    Maybe it uses a short to read KB?
    Not sure... any ideas?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fread problems or memory problems
    By Lechuza in forum C Programming
    Replies: 1
    Last Post: 03-22-2009, 12:45 PM
  2. Another link from Microsoft about bug in fread
    By vart in forum A Brief History of
    Replies: 2
    Last Post: 05-06-2008, 11:56 AM
  3. Why is fread sometimes taking so long?
    By manugarciac in forum C++ Programming
    Replies: 2
    Last Post: 04-28-2007, 11:25 PM
  4. Replies: 3
    Last Post: 01-08-2004, 08:43 PM
  5. hi need help with credit limit program
    By vaio256 in forum C++ Programming
    Replies: 4
    Last Post: 03-31-2003, 11:23 PM
Website Security Test