Preventing crashes with massive memory usage

Is there a way to avoid crashes when the memory usage in a 32 bit application is too heavy?
I’m asking this because loading 3 instances of a plugin like superior drummer (which uses loads of ram) in the Juce audio plugin host leads to runtime errors and it looks like there’s nothing I can do about it (at least under win32).
Maybe some compiler options to set?
It would be great to have a mechanism to prevent the massive load and then pop up a message to inform the user about the issue…

I don’t know of much that you could do. There might be an OS call you could make that would tell you how much RAM the whole app is using, and warn the user when it goes over some threshold, e.g. 1.5GB, but I’ve never tried anything like that.

[quote=“masshacker”]Is there a way to avoid crashes when the memory usage in a 32 bit application is too heavy?
I’m asking this because loading 3 instances of a plugin like superior drummer (which uses loads of ram) in the Juce audio plugin host leads to runtime errors and it looks like there’s nothing I can do about it (at least under win32).
Maybe some compiler options to set?
It would be great to have a mechanism to prevent the massive load and then pop up a message to inform the user about the issue…[/quote]

You need to do an estimation of the RAM used by each instance beforehand.

T = RAM total size.
F = RAM free.
E = Estimation of the max. peak of RAM that will be used by the new instance.
S = % of T (Security margin, for example, 25% of T).

if F - (E + S) <= 0 then
__MsgBox "Sorry, not enough RAM available…"
else
__CreateNewInstance(…)
endif