title: Self-limit heap size in C++
body: <p>I am concerned that a C++ program may consume an unacceptably large amount of memory. Rather than rudely gobbling up all possible RAM and swap before going down in flames, I would prefer to have the program limit itself to some maximum amount of heap memory, and have allocations fail when this is exceeded. Ideally, I want to make the maximum heap size a command-line parameter for my program, similar to the <code>-Xmx</code> option for the Java Virtual Machine. Short of manually bean-counting every little allocation, is there any language feature which could enable this?</p>