Let's say I've have a resource intensive program that works better the more memory it has, up to the computers entire available memory. I want to be able to use all of the memory I can without stopping other programs on the computer from using memory if they need it.
To get the best of both worlds I want some way for my program to be signaled by the OS if another process wants memory and give me a chance to give it up gracefully and let both programs continue happily.
Is such a thing possible to achieve in c++? If so how can it be achieved (on both Windows and Unix systems)?
Edit:
Based on the given comments, it seems that the answer is a no, this is simply not possible exactly as stated, though a workaround is feasible using the methods from How to get memory usage at runtime using C++? to dynamically detect if the memory is running low and free memory accordingly to achieve similar (though not precisely the same) results.