다음을 통해 공유


allocator 클래스

템플릿 클래스는 저장소 할당 및 형식 형식의 개체에 대한 배열 해제를 관리하는 개체를 설명합니다. An object of class allocator is the default allocator object specified in the constructors for several container template classes in the Standard C++ Library.

template <class Type> 
class allocator

매개 변수

  • 형식
    The type of object for which storage is being allocated or deallocated.

설명

All the Standard Template Library containers have a template parameter that defaults to allocator. Template class allocator supplies several type definitions that are rather pedestrian. They hardly seem worth defining. But another class with the same members might choose more interesting alternatives. Constructing a container with an allocator object of such a class gives individual control over allocation and freeing of elements controlled by that container.

For example, an allocator object might allocate storage on a private heap. It might allocate storage on a far heap, requiring nonstandard pointers to access the allocated objects. It might also specify, through the type definitions it supplies, that elements be accessed through special accessor objects that manage shared memory, or perform automatic garbage collection. Hence, a class that allocates storage using an allocator object should use these types for declaring pointer and reference objects, as the containers in the Standard C++ Library do.

When you derive from allocator class, you have to provide a rebind struct, whose _Other typedef references your newly-derived class.

Thus, an allocator defines the following types:

These Types specify the form that pointers and references must take for allocated elements. (allocator::pointer is not necessarily the same as Type* for all allocator objects, even though it has this obvious definition for class allocator.)

멤버

생성자

할당자

Constructors used to create allocator objects.

형식 정의

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.

포인터

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 can allocate.

value_type

A type that is managed by the allocator.

멤버 함수

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.

rebind

A structure that enables an allocator for objects of one type to allocate storage for objects of another type.

연산자

operator=

Assigns one allocator object to another allocator object.

요구 사항

Header: <memory>

네임스페이스: std

참고 항목

참조

C++ 표준 라이브러리의 스레드 보안

기타 리소스

구성원 할당

<memory> 멤버