Alex Rivera | Logout

How do I force a program to appear to run out of memory?

Asked 2009-08-04T18:50:22.377
30

I have a C/C++ program that might be hanging when it runs out of memory. We discovered this by running many copies at the same time. I want to debug the program without completely destroying performance on the development machine. Is there a way to limit the memory available so that a new or malloc will return a NULL pointer after, say, 500K of memory has been requested?

Edit
Report

1 Answer

3

That depends on your platform. For example, this can be achieved programmatically on Unix-like platforms using setrlimit(RLIMIT_DATA, ...).

EDIT:

The RLIMIT_AS resource may also be useful in this case as well.

answered 2009-08-04T18:58:56.087

Your Answer