STL Allocator

Components responsible for memory allocation and deallocation for STL containers.

Allocation Policy

Abstraction that encapsulates the logic to allocate and deallocate memory.

Header file: sneaker/allocator/alloc_policy.h

class sneaker::allocator::standard_alloc_policy<T>

A default implementation of allocation policy using dynamic memory allocation and deallocation from the operating system.

type value_type

The underling type that memory will be allocated for.

type pointer

Pointer type of the memory allocated by this policy.

type const_pointer

Constant pointer type of the memory allocated by this policy.

type reference

Reference type of memory allocated by this policy.

type const_reference

Constant reference type of memory allocated by this policy.

type size_type

Type used for denoting the quantity of elements allocated by this policy.

type difference_type

Type used for denoting the size difference between two pointers allocated by this policy.

type propagate_on_container_move_assignment

Indicates that the policy shall propagate when the STL container is move-assigned.

type rebind<U>

Equivalent allocator type to allocate elements of type U.

explicit standard_alloc_policy()

Explicit constructor.

~standard_alloc_policy()

Destructor.

explicit standard_alloc_policy(standard_alloc_policy const&)

Explicit copy constructor. The argument is an instance of standard_alloc_policy with the same encapsulating type. Nothing is copied over.

template<typename U>
explicit standard_alloc_policy(standard_alloc_policy<U> const&)

Explicit copy constructor. The argument is an instance of standard_alloc_policy with a different encapsulating type. Nothing is copied over.

pointer allocate(size_type, typename std::allocator<void>::const_pointer = 0)

Allocates a specified number of memory in bytes. The first argument specifies the number of bytes requested for allocation. The second argument may be a value previously obtained by another call to allocate and not yet freed with deallocate. This value may be used as a hint to improve performance by allocating the new block near the one specified.

If allocation is successful, a pointer that points to the memory allocated is returned, otherwise std::bad_alloc is raised.

void deallocate(pointer, size_type)

Deallocates the pre-allocated memory. The first argument is a pointer that points to the memory that needs to be freed, and the second argument specifies the size of the memory in bytes.

size_type max_size() const

Get the maximum amount of memory that can be allocated, in number of bytes.

template<typename T, typename T2>
bool operator==(standard_alloc_policy<T> const&, standard_alloc_policy<T2> const&)

Equality comparison between two instances of standard_alloc_policy with potentially different encapsulating type. Returns true by default.

template<typename T, typename T2>
bool operator!=(standard_alloc_policy<T> const&, standard_alloc_policy<T2> const&)

Inequality comparison between two instances of standard_alloc_policy with potentially different encapsulating type. Returns false by default.

template<typename T, typename other_allocator>
bool operator==(standard_alloc_policy<T> const&, other_allocator const&)

Equality comparison between two an instances of standard_alloc_policy and a different type. Returns false by default.

template<typename T, typename other_allocator>
bool operator!=(standard_alloc_policy<T> const&, other_allocator const&)

Inequality comparison between two an instances of standard_alloc_policy and a different type. Returns true by default.

Object Traits

Abstraction that control the construction and destruction of the encapsulating type.

Header file: sneaker/allocator/object_traits.h

class sneaker::allocator::object_traits<T>

A default implementation of object traits, where the construction and destruction of the underlying type is carried over by calling the type’s constructor and destructor respectively.

type rebind<U>

Equivalent object traits type of encapsulating type U.

explicit object_traits()

Explicit constructor.

~object_traits()

Destructor.

T *address(T&)

Get the address on a reference of an instance of the encapsulating type.

T const *address(T const&)

Get the address on a constant reference of an instance of the encapsulating type.

void construct(T *, const T&)

Instantiates an instance of the encapsulating type through copy semantics by using the specified allocated memory and an instance of the encapsulating type to be passed to the copy constructor of the instance to be created.

template<class U, class... Args>
void construct(U *, Args&&...)

Instantiates an instance of type U by using the specified allocated memory and the arguments used for instantiation. The first argument is a pointer that points to the pre-allocated memory and the remain arguments are arguments passed to the constructor of type U.

void destroy(T *)

Destroy an instantiated instance of the encapsulating type by calling the type’s destructor. The specified argument is a pointer that points to an instance of the encapsulating type.

Allocator

Abstraction that’s responsible for allocating and deallocating memory used by STL containers.

Header file: sneaker/allocator/allocator.h

class sneaker::allocator::allocator<T, Policy, Traits>

A default implementation of STL allocator based on the abstraction of allocation policy and object traits.

type value_type

The underlying type that memory will be allocated for.

type pointer

Pointer type of the memory allocated by this allocator.

type const_pointer

Constant pointer type of the memory allocated by this allocator.

type reference

Reference type of memory allocated by this allocator.

type const_reference

Constant reference type of memory allocated by this allocator.

type size_type

Type used for denoting the quantity of elements allocated by this allocator.

type difference_type

Type used for denoting the size difference between two pointers allocated by this allocator.

explicit allocator()

Explicit constructor.

~allocator()

Destructor.

allocator(allocator const &rhs)

Copy constructor that takes another allocator of the same encapsulating type. Nothing is copied over.

template<typename U>
allocator(allocator<U> const&)

Copy constructor that takes another allocator of a different encapsulating type. Nothing is copied over.

template <typename U, typename P, typename T2>
allocator(allocator<U, P, T2> const &rhs)

Copy constructor that takes another allocator of a different encapsulating type, as well as different allocation policy and object traits. Nothing is copied over.

template<typename T, typename P, typename Tr>
bool operator==(allocator<T, P, Tr> const&, allocator<T, P, Tr> const&)

Equality operator that evaluates equality between two instances of allocator that have the same encapsulating type, and are based on the same allocation policy and object traits types. Equality is evaluated based on the equality between the allocation policy types.

template<typename T, typename P, typename Tr, typename T2, typename P2, typename Tr2>
bool operator==(allocator<T, P, Tr> const&, allocator<T2, P2, Tr2> const&)

Equality operator that evaluates equality between two instances of allocator that have different encapsulating types, and are based on different allocation policy and object traits. Equality is evaluated based on the equality between the allocation policy types.

template<typename T, typename P, typename Tr, typename other_allocator>
bool operator==(allocator<T, P, Tr> const&, other_allocator const&)

Equality operator that evaluates equality between two instances of allocator that have potentially the same encapsulating types, and are based on the same allocation policy and object traits. Equality is evaluated based on the equality between the allocation type of the first argument and the second argument.

template<typename T, typename P, typename Tr>
bool operator!=(allocator<T, P, Tr> const&, allocator<T, P, Tr> const&)

Inequality operator that evaluates inequality between two instances of allocator that have the same encapsulating type, and are based on the same allocation policy and object traits. Inequality is evaluated based on the inequality between the allocation policy types.

template<typename T, typename P, typename Tr, typename T2, typename P2, typename Tr2>
bool operator!=(allocator<T, P, Tr> const&, allocator<T2, P2, Tr2> const&)

Inequality operator that evaluates inequality between two instances of allocator that have different encapsulating types, and are based on different allocation policy and object traits. Inequality is evaluated based on the inequality between the allocation policy types.

template<typename T, typename P, typename Tr, typename other_allocator>
bool operator!=(allocator<T, P, Tr> const&, other_allocator const&)

Inequality operator that evaluates inequality between two instances of allocator that have potentially different encapsulating types, and are based on different allocation policy and object traits. Inequality is evaluated based on the equality between the allocation type of the first argument and the second argument.