WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
wpi::memory::out_of_memory Class Reference

The exception class thrown when a low level allocator runs out of memory. More...

#include <wpi/memory/error.hpp>

Inheritance diagram for wpi::memory::out_of_memory:
wpi::memory::out_of_fixed_memory

Public Types

using handler = void (*)(const allocator_info& info, std::size_t amount)
 The type of the handler called in the constructor of out_of_memory.
 

Public Member Functions

 out_of_memory (const allocator_info &info, std::size_t amount)
 
const char * what () const noexcept override
 
const allocator_infoallocator () const noexcept
 
std::size_t failed_allocation_size () const noexcept
 

Static Public Member Functions

static handler set_handler (handler h)
 
static handler get_handler ()
 

Detailed Description

The exception class thrown when a low level allocator runs out of memory.

It is derived from std::bad_alloc. This can happen if a low level allocation function like std::malloc() runs out of memory. Throwing can be prohibited by the handler function.

Member Typedef Documentation

◆ handler

using wpi::memory::out_of_memory::handler = void (*)(const allocator_info& info, std::size_t amount)

The type of the handler called in the constructor of out_of_memory.

When an out of memory situation is encountered and the exception class created, this handler gets called. It is especially useful if exception support is disabled. It gets the allocator_info and the amount of memory that was tried to be allocated.

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.
Note
It is different from std::new_handler; it will not be called in a loop trying to allocate memory or something like that. Its only job is to report the error.

Constructor & Destructor Documentation

◆ out_of_memory()

wpi::memory::out_of_memory::out_of_memory ( const allocator_info & info,
std::size_t amount )
Effects:
Creates it by passing it the allocator_info and the amount of memory failed to be allocated. It also calls the handler to control whether or not it will be thrown.

Member Function Documentation

◆ allocator()

const allocator_info & wpi::memory::out_of_memory::allocator ( ) const
inlinenoexcept
Returns:
The allocator_info passed to it in the constructor.

◆ failed_allocation_size()

std::size_t wpi::memory::out_of_memory::failed_allocation_size ( ) const
inlinenoexcept
Returns:
The amount of memory that was tried to be allocated. This is the value passed in the constructor.

◆ get_handler()

static handler wpi::memory::out_of_memory::get_handler ( )
static
Returns:
The current handler. This is never nullptr.

◆ set_handler()

static handler wpi::memory::out_of_memory::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.

◆ what()

const char * wpi::memory::out_of_memory::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: