简体   繁体   中英

Any disadvantage of storing file handles over whole program execution?

Im currently working on a projects which maps all avaible resources (files) at beginning of its execution. Many of the resources might be used later but are not needed at the beginning. The resources can be read, modified and newly created.

Would there be any disadvantage of reserving all eventually needed files and storing their file handles for later? (ps. the resources are only used by this program and should not be modified externally)

In general I don't see any significant problems with such approach. But in special cases you can get problems. Conflict can happen when somebody else will decide to use the same files.

  • you run your program twice and second processes will try to open the same files

  • system services can affect files. Maybe you have cron set up to archive your files

  • you open file for writing. File is created, but nothing is written there. As a result you generated empty file without reason

And anyway it is a good manner not to reserve resource if you don't need it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM