Closed notmgsk closed 4 years ago
I don't think this will be very robust. I'd rather check there's enough free space before allocating the vector, and doing this as a last resort.
To add to my previous comment, sometimes an error is signaled, sometimes not. Running out of memory is a really tough situation. For the most part, memory will run out because a request is simply outrageous. Sometimes, there might not even be enough memory to handle the error itself.
I'm happy for an alternative viewpoint / a test of some sort.
It isn't robust, agreed. My original thought was also to see if enough memory was available before trying to allocate. I think I avoided doing that because I wasn't sure how to accurately calculate the memory required for a given request or how to ask SBCL how much memory is free. Please don't suggest (room)
ðŸ˜
I'd suggest the following:
Create a function (allocation-will-likely-fail-p num-bytes)
Ask SBCL folks what the best way to implement this is.
#+sbcl
the implementation
#-sbcl nil
otherwise
Do a (when (allocation-... ...) (error ...))
How does that sound?
Heap exhaustion errors aren't reported politely to pyquil, instead we see something like
With this PR a more helpful error message is provided.