A very similar question was asked for the .net
Windows environment:
How do you protect yourself from runaway memory consumption bringing down the PC?
This question is posed for the Unix environment using C or C++. As an example, consider the dangerous little block below:
#include <vector>
int main() {
int n;
std::vector<double> A(n);
}
If you're lucky the code will throw a range error. If you're unlucky (in my case the value of a in memory was 283740392) the code will quickly use all the available RAM and cause massive swapping to disk, grinding the OS to a virtual standstill faster then it can be killed. The process can always be killed eventually of course, but it may often take minutes to recover as all the other running processes have to be loaded back into memory. This is not a question whose answer implies a lack of RAM, one could easily give a runaway process that swamps any available machine.