-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fallible memory allocation #423
Comments
So I like the principle of making a more principled error message from failed allocation. My big concern is that it needs to not affect the fast path. As such I am concerned about passing around a wrapper as you propose as it will likely affect the perf. I wonder if we want the allocator to have a field for the last error code, and then that can be inspected on a Then, various points that convert failure into a
like feature. That returns the reason for a Also with SNMALLOC_CHECK_CLIENT there are a second class of errors. Personally, I think these should be handled differently. @nwf, @davidchisnall any thoughts? |
Thanks for the reply! I meant to develop two separate paths (fallible and infallible) on par. But with the above discussion, maybe it can be easier to use sth like
|
My concern with two paths is the code uses a lot of tail recursive calls that get optimised into jumps. This might be tricky to maintain if there are two continuations. But I am happy to look at a sketch of any design. |
I'm nervous of setting a field in a structure because that's hard for the compiler to elide. I wonder if we could add an extra template parameter (what's one more, between friends?) to the alloc functions to take an error delegate that is called with the error code? The Rust functions would then pass a lambda that set a local variable to this and, after all of the inlining, it should just be an extra register update. The malloc ones would take the default empty function which, after inlining, should not disrupt codegen at all. |
Client language like rust may want to provide fallible memory allocation APIs.
https://rust-lang.github.io/rfcs/2116-alloc-me-maybe.html
It is of course not a required feature. The std library states that
Alloc
implementation is allowed to be implemented on top of a native allocator that aborts on allocation failure. However, it can be good is consider support fallible allocation in snmalloc.I am now prototyping this with the structure above. We can provide sth like the following on par:
But it may require a big refactor across the project to finally support the feature.
The text was updated successfully, but these errors were encountered: