cptr::allocator

A standard allocator that places objects in the cage, so that any std container's elements can be pointed to with a 4-byte cptr::ptr.

Synopsis

Declared in <cptr/allocator.hpp>

template<
    class T,
    class Cage = default_cage>
class allocator;

Description

The container's own links stay 8 bytes; for 4-byte links use the cptr containers, or fancy_allocator with a container that supports fancy pointers.


std::vector<node, cptr::allocator<node>> nodes(1000);
cptr::ptr<node> first = &nodes[0];  // the elements are in the cage

Types

NameDescription
rebind The same allocator for another element type.

Type Aliases

NameDescription
cage_type The cage the elements are allocated in.
value_type The element type.

Member Functions

NameDescription
allocator [constructor]Constructors
allocate Memory for n T in the cage, uninitialised. Throws std::bad_array_new_length if n exceeds max_size(), and std::bad_alloc when the cage is full.
deallocate Frees memory from allocate(); the elements must already be destroyed.
max_size The most T that one allocation could hold: no more than fit in the cage.

Friends

NameDescription
cptr::operator==Always true: memory from one allocator for a cage can be freed by any other for the same cage.