Skip to content

Docs: std::alloc::set_alloc_error_hook clarifications #56965

Open
@brson

Description

@brson

In using this function I am wondering a few things:

  • What happens if I oom while handling an oom? Is the oom handler called again? Does the process immediately abort (ala panic)?

  • Does triggering oom remove the custom oom handler? The presence of take_alloc_error_hook makes it seem like that may the case, but it is not. It looks like the custom handler stays in place through its invocation. Docs would be better to mention that it's possible to oom recursively and invoke your oom handler recursively.

  • Is OOM the only time that memory allocation fails? The document doesn't mention "out of memory", but the situation this handles is commonly called "OOM". The docs would better mention "out of memory" and whether there is a distinction between allocation failure types.

  • Does take_alloc_error_hook restore the default error hook?

Are the answers to these questions known and intended? Please add them to the docs.

Here are some harder questions:

Can I and should I try to recover from an oom? The oom handling mechanism calls abort after calling the oom handler, but what if I panic in the handler?

I could empty my caches or otherwise mess with the allocator, panic, catch the panic, and try to continue. Is that a valid and intended use case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions