The exception class thrown when an allocation size is bigger than the supported maximum.
More...
#include <wpi/memory/error.hpp>
The exception class thrown when an allocation size is bigger than the supported maximum.
This size is either the node, array or alignment parameter in a call to an allocation function. If those exceed the supported maximum returned by max_node_size()
, max_array_size()
or max_alignment()
, one of its derived classes will be thrown or this class if in a situation where the type is unknown. It is derived from std::bad_alloc
. Throwing can be prohibited by the handler function.
- Note
- Even if all parameters are less than the maximum, out_of_memory or a similar exception can be thrown, because the maximum functions return an upper bound and not the actual supported maximum size, since it always depends on fence memory, alignment buffer and the like.
-
A user should only
catch
for bad_allocation_size
, not the derived classes.
-
Most checks will only be done if WPI_MEMORY_CHECK_ALLOCATION_SIZE is
true
.
◆ handler
Initial value: void (*)(const allocator_info& info, std::size_t passed,
std::size_t supported)
The type of the handler called in the constructor of bad_allocation_size.
When a bad allocation size is detected and the exception object created, this handler gets called. It is especially useful if exception support is disabled. It gets the allocator_info, the size passed to the function and the supported size (the latter is still an upper bound).
- Required Behavior:
- It can log the error, throw a different exception derived from
std::bad_alloc
or abort the program. If it returns, this exception object will be created and thrown.
- Default Behavior:
- On a hosted implementation it logs the error on
stderr
and continues execution, leading to this exception being thrown. On a freestanding implementation it does nothing.
◆ bad_allocation_size()
wpi::memory::bad_allocation_size::bad_allocation_size |
( |
const allocator_info & | info, |
|
|
std::size_t | passed, |
|
|
std::size_t | supported ) |
- Effects:
- Creates it by passing it the allocator_info, the size passed to the allocation function and an upper bound on the supported size. It also calls the handler to control whether or not it will be thrown.
◆ allocator()
const allocator_info & wpi::memory::bad_allocation_size::allocator |
( |
| ) |
const |
|
inlinenoexcept |
◆ get_handler()
static handler wpi::memory::bad_allocation_size::get_handler |
( |
| ) |
|
|
static |
- Returns:
- The current handler. This is never
nullptr
.
◆ passed_value()
std::size_t wpi::memory::bad_allocation_size::passed_value |
( |
| ) |
const |
|
inlinenoexcept |
- Returns:
- The size or alignment value that was passed to the allocation function which was too big. This is the same value passed to the constructor.
◆ set_handler()
static handler wpi::memory::bad_allocation_size::set_handler |
( |
handler | h | ) |
|
|
static |
- Effects:
- Sets
h
as the new handler in an atomic operation. A nullptr
sets the default handler.
- Returns:
- The previous handler. This is never
nullptr
.
◆ supported_value()
std::size_t wpi::memory::bad_allocation_size::supported_value |
( |
| ) |
const |
|
inlinenoexcept |
- Returns:
- An upper bound on the maximum supported size/alignment. It is only an upper bound, values below can fail, but values above will always fail.
◆ what()
const char * wpi::memory::bad_allocation_size::what |
( |
| ) |
const |
|
overridenoexcept |
- Returns:
- A static NTBS that describes the error. It does not contain any specific information since there is no memory for formatting.
The documentation for this class was generated from the following file: