1

I have a C++ Class with an std::ifstream attribute. Every object of this class on creation takes a file path in the constructor, opens the file and using the std::ifstream attribute and keeps it open during the lifetime of the object.

Somewhere else in the code, at a later point, I read a .ini file using the boost::property_tree::read_ini function.

Everything works as it should in the normal case. However, when I create more than 254 instances of above class having the std::ifstream attribute, the totally unrelated code of reading the .ini file fails and I get a std::runtime_error with "cannot open file" in the exception.what() message.

This makes me wonder if I'm not allowed to keep more than a certain number of open std::ifstream references.

Can anyone point out if this is the case or if I'm missing something?

Edit: - I'm using Windows x64 system

locke14
  • 1,335
  • 3
  • 15
  • 36
  • 2
    *This makes me wonder if I'm not allowed to keep more than a certain number of open `std::ifstream` references.* The language does not have any restrictions but OS's do. After all, they don't have unlimited resources. – R Sahu Apr 11 '19 at 17:42
  • What platform? What resource limits? If this is a UNIXy platform, what the output of `ulimit -n`? – David Schwartz Apr 11 '19 at 17:44
  • I'm using a windows 64 bit system using Visual Studio 2017 – locke14 Apr 11 '19 at 17:45
  • 1
    Keeping > 200 files open??? Ever thought of that your design might be flawed? – Aconcagua Apr 11 '19 at 17:46
  • @Aconcagua if you think having 200 files open is a design flaw, apparently you never build a database system. – SergeyA Apr 11 '19 at 17:49
  • @SergeyA If there's a limit for open file descriptors, it would apply for the DMBS as well. So if it relies on, it wouldn't be able to run on any OS imposing such a limit. Pretty sure a non-naive DBMS finds better ways to handle the issue... (Although, admitted, a certain number of open files still will be required.) – Aconcagua Apr 11 '19 at 18:16
  • This limit is in the MSVC's standard library implementation, not the OS. You can increase the limit if necessary. Details in the older post. – Adrian McCarthy Apr 11 '19 at 18:18

0 Answers0