fread item_size limit

This is a discussion on fread item_size limit within the C++ Programming forums, part of the General Programming Boards category; I'm using the function fread to read binary data from files. According to the MSDN, fread has the following parameters: ...

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

    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
    );

    Parameters:

    buffer
    Storage location for data.

    size
    Item size in bytes.

    count
    Maximum number of items to be read.

    stream
    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.
    hth
    -nv

    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
    Location
    Brazil, Porto Alegre
    Posts
    152
    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:
    Code:
    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:
    Code:
    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
    Location
    Brazil, Porto Alegre
    Posts
    152
    Uhm...
    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, 01:45 PM
  2. Another link from Microsoft about bug in fread
    By vart in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-06-2008, 12:56 PM
  3. Why is fread sometimes taking so long?
    By manugarciac in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2007, 12:25 AM
  4. Replies: 3
    Last Post: 01-08-2004, 09:43 PM
  5. hi need help with credit limit program
    By vaio256 in forum C++ Programming
    Replies: 4
    Last Post: 04-01-2003, 12:23 AM

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