다음을 통해 공유


allocator_base Class

 

The latest version of this topic can be found at allocator_base Class.

Defines the base class and common functions needed to create a user-defined allocator from a synchronization filter.

Syntax

template <class Type, class Sync>  
class allocator_base

Parameters

Parameter Description
Type The type of elements allocated by the allocator.
Sync The synchronization policy for the allocator, which is sync_none Class, sync_per_container Class, sync_per_thread Class, or sync_shared Class.

Constructors

allocator_base Constructs an object of type allocator_base.

TypeDefs

const_pointer A type that provides a constant pointer to the type of object managed by the allocator.
const_reference A type that provides a constant reference to type of object managed by the allocator.
difference_type A signed integral type that can represent the difference between values of pointers to the type of object managed by the allocator.
pointer A type that provides a pointer to the type of object managed by the allocator.
reference A type that provides a reference to the type of object managed by the allocator.
size_type An unsigned integral type that can represent the length of any sequence that an object of template class allocator_base can allocate.
value_type A type that is managed by the allocator.

Member Functions

_Charalloc Allocates storage for an array of type char.
_Chardealloc Frees storage for the array containing elements of type char.
address Finds the address of an object whose value is specified.
allocate Allocates a block of memory large enough to store at least some specified number of elements.
construct Constructs a specific type of object at a specified address that is initialized with a specified value.
deallocate Frees a specified number of objects from storage beginning at a specified position.
destroy Calls an objects destructor without deallocating the memory where the object was stored.
max_size Returns the number of elements of type Type that could be allocated by an object of class allocator before the free memory is used up.

Requirements

Header: <allocators>

Namespace: stdext

allocator_base::_Charalloc

Allocates storage for an array of type char.

char *_Charalloc(size_type count);

Parameters

Parameter Description
count The number of elements in the array to be allocated.

Return Value

A pointer to the allocated object.

Remarks

This member function is used by containers when compiled with a compiler that cannot compile rebind. It implements _Charalloc for the user-defined allocator by returning the result of a call to the allocate function of the synchronization filter.

allocator_base::_Chardealloc

Frees storage for the array containing elements of type char.

void _Chardealloc(void* ptr, size_type count);

Parameters

Parameter Description
ptr A pointer to the first object to be deallocated from storage.
count The number of objects to be deallocated from storage.

Remarks

This member function is used by containers when compiled with a compiler that cannot compile rebind. It implements _Chardealloc for the user-defined allocator by calling the deallocate function of the synchronization filter. The pointer ptr must have been earlier returned by a call to _Charalloc for an allocator object that compares equal to *this, allocating an array object of the same size and type. _Chardealloc never throws an exception.

allocator_base::address

Finds the address of an object whose value is specified.

pointer address(reference val);

const_pointer address(const_reference val);

Parameters

val
The const or nonconst value of the object whose address is being searched for.

Return Value

A const or nonconst pointer to the object found of, respectively, const or nonconst value.

Remarks

This member function is implemented for the user-defined allocator by returning &val.

allocator_base::allocate

Allocates a block of memory large enough to store at least some specified number of elements.

template <class Other>  
pointer allocate(size_type _Nx, const Other* _Hint = 0);

pointer allocate(size_type _Nx);

Parameters

Parameter Description
_Nx The number of elements in the array to be allocated.
_Hint This parameter is ignored.

Return Value

A pointer to the allocated object.

Remarks

The member function implements memory allocation for the user-defined allocator by returning the result of a call to the allocate function of the synchronization filter of type Type * if _Nx == 1, otherwise by returning the result of a call to operator new(_Nx * sizeof(Type)) cast to type Type *.

allocator_base::allocator_base

Constructs an object of type allocator_base.

allocator_base();

template <class Other>  
allocator_base(const allocator_base<Other, Sync>& right);

Parameters

Parameter Description
right The allocator object to be copied.

Remarks

The first constructor constructs an allocator_base instance. The second constructor constructs an allocator_base instance such that for any allocator_base<Type, _Sync> instance a, allocator_base<Type, Sync>(allocator_base<Other, Sync>(a)) == a.

allocator_base::const_pointer

A type that provides a constant pointer to the type of object managed by the allocator.

typedef const Type *const_pointer;

allocator_base::const_reference

A type that provides a constant reference to type of object managed by the allocator.

typedef const Type& const_reference;

allocator_base::construct

Constructs a specific type of object at a specified address that is initialized with a specified value.

void construct(pointer ptr, const Type& val);

Parameters

Parameter Description
ptr A pointer to the location where the object is to be constructed.
val The value with which the object being constructed is to be initialized.

Remarks

This member function is implemented for the user-defined allocator by calling new((void*)ptr Type(val).

allocator_base::deallocate

Frees a specified number of objects from storage beginning at a specified position.

void deallocate(pointer ptr, size_type _Nx);

Parameters

Parameter Description
ptr A pointer to the first object to be deallocated from storage.
_Nx The number of objects to be deallocated from storage.

Remarks

This member function is implemented for the user-defined allocator by calling deallocate(ptr) on the synchronization filter Sync if _Nx == 1, otherwise by calling operator delete(_Nx * ptr).

allocator_base::destroy

Calls an objects destructor without deallocating the memory where the object was stored.

void destroy(pointer ptr);

Parameters

Parameter Description
ptr A pointer designating the address of the object to be destroyed.

Remarks

This member function is implemented for the user-defined allocator by calling ptr->~Type().

allocator_base::difference_type

A signed integral type that can represent the difference between values of pointers to the type of object managed by the allocator.

typedef std::ptrdiff_t difference_type;

allocator_base::max_size

Returns the number of elements of type Type that could be allocated by an object of class allocator before the free memory is used up.

size_type max_size() const;

Return Value

The number of elements that could be allocated.

Remarks

This member function is implemented for the user-defined allocator by returning (size_t)-1 / sizeof(Type) if 0 < (size_t)-1 / sizeof(Type), otherwise 1.

allocator_base::pointer

A type that provides a pointer to the type of object managed by the allocator.

typedef Type *pointer;

allocator_base::reference

A type that provides a reference to the type of object managed by the allocator.

typedef Type& reference;

allocator_base::size_type

An unsigned integral type that can represent the length of any sequence that an object of template class allocator_base can allocate.

typedef std::size_t size_type;

allocator_base::value_type

A type that is managed by the allocator.

typedef Type value_type;

See Also

<allocators>