ReadFile()" function is failing with error ERROR_NO_SYSTEM_RESOURCES

Hello Experts,

A call to the WIN32 "ReadFile()" function is failing with error ERROR_NO_SYSTEM_RESOURCES (1450).  I am assuming that I am running into some limitation on file handles, or internal file buffers or whatever, since when the error occurs 76 files have previously been opened (and remain open at the time of the error).

Is there a limit on how many files can be opened?  If yes, how can I get around the file limit problem in WIN32?

LVL 11
Who is Participating?
cookreConnect With a Mentor Commented:
That error has many causes, the most common of which is running out of RAM.

Do you allocate lots of big buffers without releasing?
Do any recursion?
Do you have other big apps open?
If you're running this in debug mode from the compiler, make a release version and try it.

The once specific limit on file handles no longer obtains, rather, there's a limit on handles in general, for which there's a specific error code.
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
I don't about an specific number of handlers you can open at a time, but it must be a high value (more than 76), but, if ReadFile() gives you an error, how could you opened the file? are you checking open function result?
Is it absolutely necessary to open 76 files at a time? I guess you have another alternative.
Also check your memory resources when opening files.
mohammadzahidAuthor Commented:
Thanks guys for the recommendations and help. I will try them and post questions if any.

Thank you.

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

adg080898Connect With a Mentor Commented:
You are probably reading too much data at once. How many bytes are you asking to read in each ReadFile call? I know for sure that windows sockets have major problems with blocks more than 64KB in a single call. Disk drivers may have problems like this as well (with much more than 64KB of course).

Disk drivers may have limitations on how much data they can read in one shot. Perhaps the DMA hardware cannot handle so many pages in one scatter-read. Also, the disk cache can only lock-down a limited number of pages, so it might even be a software limitation.

Try keeping your reads definitely less than 16 megabytes, preferably less than 1 megabyte, in a single call.
Are you opening the file with FILE_FLAG_NO_BUFFERING? That asks for trouble...
Jaime OlivaresSoftware ArchitectCommented:
Still waiting for author's feedback
mohammadzahidAuthor Commented:
I have not had time to test the suggestions posted by the experts as I am extremely busy with a very important project.
I am anticipated to try the expert's suggestions in a week or 2.

Please do not clean or delete this thread for 2 weeks.

mohammadzahidAuthor Commented:
My application was reading too much data and was not deallocating buffer.
Problem resolved by reducing the number of file, reading small chuck of data into memory and free when not needed.

Points distributed evenly among experts as all of the responses provided a good lead to analyze and detect the source of the problem.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.