ALLOCATORS:
In C++
computer programming, allocators are an important component of the C++ Standard
Library. The standard library provides several data structures, such as list
and set, commonly referred to as containers. A common trait among these
containers is their ability to change size during the execution of the program.
It encapsulates a memory allocation and deallocation strategy.
Every
standard library component that may need to allocate or release storage, from
std::string, std::vector, and every container except std::array, to
std::shared_ptr and std::function, does so through an Allocator: an object of a
class type that satisfies the following requirements.
Requirements
·
A, an Allocator type for type T
·
a, an object of type A
·
B, the corresponding Allocator type for type U (as
obtained by rebinding A)
·
ptr, a value of type
allocator_traits<A>::pointer, obtained by calling
allocator_traits<A>::allocate()
·
cptr, a value of type allocator_traits<A>::const_pointer,
obtained by conversion from ptr
·
vptr, a value of type
allocator_traits<A>::void_pointer, obtained by conversion from ptr
·
cvptr, a value of type
allocator_traits<A>::const_void_pointer, obtained by conversion from cptr
or from vptr
·
xptr, a dereferencable pointer to some type X
Some requirements are optional: the template std::allocator_traits supplies the default implementations for all optional requirements, and all standard library containers and other allocator-aware classes access the allocator through , not directly.
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.