Singleton class to keep track of locked (ie, non‐swappable) memory, for use in std::allocator templates.

Synopsis

Declared in <support/lockedpool.h>

class LockedPoolManager
    : public LockedPool

Description

Some implementations of the STL allocate memory in some constructors (i.e., see MSVC's vector<T> implementation where it allocates 1 byte of memory in the allocator.) Due to the unpredictable order of static initializers, we have to make sure the LockedPoolManager instance exists before any other STL‐based objects that use secure_allocator are created. So instead of having LockedPoolManager also be static‐initialized, it is created on demand.

Base Classes

Name

Description

LockedPool

Pool for locked memory chunks.

Types

Name

Description

Stats

Memory statistics.

Type Aliases

Name

Description

LockingFailed_Callback

Callback when allocation succeeds but locking fails.

Member Functions

Name

Description

operator= [deleted]

Deleted copy assignment; a LockedPool cannot be copied.

alloc

Allocate size bytes from this arena. Returns pointer on success, or 0 if memory is full or the application tried to allocate 0 bytes.

free

Free a previously allocated chunk of memory. Freeing the zero pointer has no effect. Raises std::runtime_error in case of error.

stats

Get pool usage statistics

Static Member Functions

Name

Description

Instance

Return the current instance, or create it once

Static Data Members

Name

Description

ARENA_ALIGN

Chunk alignment. Another compromise. Setting this too high will waste memory, setting it too low will facilitate fragmentation.

ARENA_SIZE

Size of one arena of locked memory. This is a compromise. Do not set this too low, as managing many arenas will increase allocation and deallocation overhead. Setting it too high allocates more locked memory from the OS than strictly necessary.

Created with MrDocs