memory
Typedefs | Static Functions | Member Functions
out_of_fixed_memory Class Reference

Detailed Description

A special case of out_of_memory errors thrown when a low-level allocator with a fixed size runs out of memory.

For example, thrown by fixed_block_allocator or static_allocator.
It is derived from out_of_memory but does not provide its own handler.

Typedefs

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

Static Functions

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

Member Functions

 out_of_fixed_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
 

Typedefs

◆ handler

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

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.

Constructors

◆ out_of_fixed_memory()

out_of_fixed_memory ( const allocator_info info,
std::size_t  amount 
)
Effects:
Just forwards to out_of_memory.

Member Functions

◆ what()

const char * 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.

◆ set_handler()

static handler set_handler ( handler  h)
staticinherited
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.

◆ get_handler()

static handler get_handler ( )
staticinherited
Returns:
The current handler. This is never nullptr.

◆ allocator()

const allocator_info & allocator ( ) const
noexceptinherited
Returns:
The allocator_info passed to it in the constructor.

◆ failed_allocation_size()

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