3 ms·
You can look at the SQLite codebase for good examples of this. Essentially, you will have to introduce a fixed upper bound for the file size you are willing to
by tooltower 5y ago
You can look at the SQLite codebase for good examples of this. Essentially, you will have to introduce a fixed upper bound for the file size you are willing to handle, given your minimum system requirements. This way, you can actually test that your program gracefully handles OOM conditions.
This page explains more on this: https://sqlite.org/limits.html https://sqlite.org/limits.html
- SigmundA 5y agoFixed upper limits are helpful but do not prevent OOM. Perhaps the system has very little free memory due to other programs or limited hardware or other reasons but your program is intended to load large files on systems that have the memory so the upper limits are pretty high. It's takes very little memory to show the user an error message it will almost always succeed even if the operation that triggered failed due to OOM.
- tooltower 5y agoOf course, it's not a guarantee. But if your program is under heavy pressure from other programs, it won't continue to run in any reasonable sense either, even without Linux's OOM-killer. Yes, you can show an error message, but then the only safe thing to do is quit. You won't even be able to clean up any on-disk swap files properly, let alone handle user interactions. Handling this is hard in desktop applications. For servers, you can have known workloads with better limits on each process.