read() api call maximum byte count on XP

Discussion in 'Windows XP Help and Support' started by perdrix, Oct 2, 2019.

  1. perdrix

    perdrix

    Joined:
    Oct 2, 2019
    Messages:
    4
    Likes Received:
    0
    When I ran some code using read() that worked fine on Windows 7 and up on XP, I got a -1 return code with errno set to EINVAL when I called it with a requested byte count of 170,769,911.

    I had thought the the limit was INT_MAX(2GB-1) but clearly not on XP! I worked around the problem by setting a maximum request length of USHRT_MAX (65535) and iterating.

    What is the actual real limit on XP? I can't quite believe it's as small as 64k-1!

    Thanks
    David
     
    perdrix, Oct 2, 2019
    #1
  2. perdrix

    Computer semi-expert

    Joined:
    Jan 13, 2019
    Messages:
    266
    Likes Received:
    85
    Location:
    State of Confusion
    Are you referring to std::istream::read()? What programming language are you using?

    If you are referring to std::istream::read(), I have no idea what's going on.
     
    Computer semi-expert, Oct 4, 2019
    #2
  3. perdrix

    perdrix

    Joined:
    Oct 2, 2019
    Messages:
    4
    Likes Received:
    0
    Nothing so complex: the regular C api call:

    int read(int fh, void* buffer, unsigned int length)

    for reading files.
     
    perdrix, Oct 6, 2019
    #3
  4. perdrix

    Computer semi-expert

    Joined:
    Jan 13, 2019
    Messages:
    266
    Likes Received:
    85
    Location:
    State of Confusion
    Well, I'm not a C programmer (only C++), so I can't help you.
     
    Computer semi-expert, Oct 7, 2019
    #4
  5. perdrix

    perdrix

    Joined:
    Oct 2, 2019
    Messages:
    4
    Likes Received:
    0
    To answer my own question! I wrote a crude binary search to determine the actual limit.

    When the file is on a local disk, then subject to memory availability (you try a malloc of 2GB under XP!!), then INT_MAX is (most likely) the limit - I couldn't reach that value!

    However the number is much lower when you are reading from a mapped network drive (in this case connecting to Host disk when running in a VM under VMWare). In that case the limit would appear to be 67,076,032 (0x3FF7FC0) bytes.

    I don't know quite why it would be that value, but likely it's a restriction in NETBIOS.

    David
     
    perdrix, Oct 10, 2019
    #5
  6. perdrix

    Computer semi-expert

    Joined:
    Jan 13, 2019
    Messages:
    266
    Likes Received:
    85
    Location:
    State of Confusion
    You poor guy! Using malloc?! Switch to C++ and you can use new. It's much easier. ;) Also, you can use std::fstream for reading files. It doesn't require a file size.

    Just my opinion, do whatever you want. :D
     
    Computer semi-expert, Oct 10, 2019
    #6
  7. perdrix

    perdrix

    Joined:
    Oct 2, 2019
    Messages:
    4
    Likes Received:
    0
    That was just a for example - actually I do use new and shared_ptr/unique_ptr a lot, just that the code I hit that problem with was OLD code so I "went with the flow" when writing the test case!

    It turns out that this MS web-page documents the limit (though not with great precision):
    https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-writefile
    and it fails to mention that those limits also apply to read operations!

    PS Love the sig-line quote about C++ and blowing your leg off!
     
    Last edited: Oct 10, 2019
    perdrix, Oct 10, 2019
    #7
  8. perdrix

    Computer semi-expert

    Joined:
    Jan 13, 2019
    Messages:
    266
    Likes Received:
    85
    Location:
    State of Confusion
    Good for you for using C++!

    Actually, good for you for being versatile and programming in a variety of languages.

    I found it somewhere and thought it was fitting, and Bjarne Stroustrup claims on his website that he actually did say it, so there it is.
     
    Computer semi-expert, Oct 11, 2019
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.