Skip to content

Provide PMR allocator of remaining memory to thrown objects #66

@kammce

Description

@kammce

Just a random idea.

Lets consider a developer using an exception block allocator like so:

std::array<exception_header<SizeOfLargestException>, NumberOfThreads * 2> m_exception_memory{};
std::pmr::montonic_memory_resource exception_memory(m_exception_memory.data(), std::as_bytes(m_exception_memory).size());

Lets assume we have a way to acquiring the value SizeOfLargestException from the compiler and NumberOfThreads from the application. With this, you'll always have storage for 2 exception objects for each thread. 2 are needed because there may be a throw E expression in a catch block which requires additional storage as the caught exception needs to outlive the current scope.

In this case, you may have an thrown object that doesn't take up SizeOfLargestException of space. Meaning if that object wants to perform an allocation, we could allocate the memory from the left over space within the block. It could be acquired via hal::get_remaining_exception_allocator_memory. (I know, I know, very long name)

Metadata

Metadata

Assignees

No one assigned

    Labels

    🔍 InvestigationA gap in our knowledge about exceptions

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions