The question is very similar to this one, however the solution proposed there doesn't satisfy me because I don't want Mathematica to abort the evalution, but simply to do it with less RAM.

Basically I'd like Mathematica to think my machine has for example only 14 Gb of RAM, let it use only those, and not abort the evaluation when it uses more than 14 Gb, like suggested there. I would like Mathematica to run as it would run in a virtual box which can only access 14 GB of RAM, but I don't want to use a virtual box

Is this possible?

If it is possible, can I trust the results obtained in this way or there's an high chance of losing important pieces during the evalution, due to the fact that mathematica would use more ram to perform that evaluation?

  • 3
    $\begingroup$ I don’t understand your point of view. When a certain amount of RAM is needed to fit a certain computation in memory, if the RAM is unavailable then the system can’t “make do with less”. It simply can’t do it. You, the programmer, will have to change your algorithm and come up with clever tricks to avoid high memory usage. $\endgroup$
    – MarcoB
    Commented Jan 5, 2020 at 19:08
  • 4
    $\begingroup$ Yes such functionality exists. You can wrap the code that may use too much memory within MemoryConstrained. That would prevent MMA from gobbling up all your memory, but it would still abort the computation if the limit is reached. $\endgroup$
    – MarcoB
    Commented Jan 5, 2020 at 19:19
  • 5
    $\begingroup$ Managing memory requests is up to the operating system. The operating system may answer to request for memory that exceed actual RAM by swapping data to disk, rather than just denying the request. “Although virtual memory allows you in principle to use large amounts of memory space, it is usually hundreds or even thousands of times slower to access than physical memory. As a result, if your calculation becomes so large that it needs to make use of virtual memory, it may run much more slowly.” $\endgroup$
    – MarcoB
    Commented Jan 5, 2020 at 19:38
  • 2
    $\begingroup$ It is possible but, if swap is in use, it might slow down so much that it would practically never finish within a reasonable time... $\endgroup$
    – MarcoB
    Commented Jan 5, 2020 at 20:39
  • 1
    $\begingroup$ @bbgodfrey I (fortunately?) have little experience of exceeding memory limits as I rarely need that much memory in what I do. In those few cases when I have hit a memory limit, I quickly backed off and took another path :-) $\endgroup$
    – MarcoB
    Commented Jan 6, 2020 at 17:43