Data types, functions, operators, constructors used by an allocator in C++

An allocator is declared as:

template <class T> class allocator

Data types used by an allocator:

pointer: Data type for a pointer to an object.

reference: Data type for a reference to an object.

const_pointer:  Data type for a const pointer to an object.

const_reference: Data type for a const reference to an object.

difference_type: Data type for representing difference between two addresses.

size_type: Data type for to hold largest possible object which can be allocated.

value_type: Data type for type of allocated object.

Functions used by allocator:

address: It is used to return a pointer to given a reference.

allocate: It is used to Allocate memory.

deallocate: It is used to free memory.

max_size: It is used to return maximum number of objects that can be allocated.

construct: It is used to construct an object.

destroy: It is used to destroy an object.

Operators used by an allocator: ==, !=

Types of constructors used by an allocator:

Type-1: To create a new allocator:

allocator( ) throw( );

Type-2: To create a copy of obj:

allocator(const allocator<T> &obj) throw( );

Leave a Reply