Catching and reporting memory allocation errors

I'm implementing a language runtime with a REPL in Rust. It's not typical that it runs out of memory, but in those rare events it does, I want to catch the allocation error and print a message to the screen indicating the lack of available memory. The problem is that there seems to be nothing to catch.. when a memory limitation is imposed with ulimit, for example, the response of the REPL to a lack of memory is to fail silently and return to the prompt. I thought with the introduction of custom allocators and catchable panics, this would be easier.. has anyone done anything similar? Thanks.

1 Like

When you are talking about ulimit are you talking about the stack size? Afaik there's no ulimit for the heap.
Can you specify that please?

I'm talking about virtual memory, which to my admittedly limited knowledge, affects the heap size (or is the heap? I'm not entirely sure). See this issue for an example:

https://github.com/mthom/scryer-prolog/issues/16

You'll be able to set oom=panic, which you can catch, once this RFC is done:

https://github.com/rust-lang/rfcs/blob/master/text/2116-alloc-me-maybe.md

5 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.