Namespaces
Variants

std::allocator_traits<Alloc>:: allocate

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
헤더 파일에 정의됨 <memory>
static pointer allocate ( Alloc & a, size_type n ) ;
(1) (C++11부터)
(C++20부터 constexpr)
static pointer allocate ( Alloc & a, size_type n, const_void_pointer hint ) ;
(2) (C++11부터)
(C++20부터 constexpr)

할당자 a 를 사용하여 n * sizeof ( Alloc :: value_type ) 바이트의 초기화되지 않은 저장 공간을 할당합니다. 해당 저장 공간에 Alloc :: value_type [ n ] 타입의 배열이 생성되지만, 그 요소들 중 어느 것도 생성되지 않습니다.

1) a. allocate ( n ) 를 호출합니다.
2) 추가적으로 메모리 지역성 힌트 hint 를 전달합니다. 가능한 경우 a. allocate ( n, hint ) 를 호출합니다. 가능하지 않은 경우(예: a 가 두 인자 멤버 함수 allocate 를 갖지 않는 경우), a. allocate ( n ) 를 호출합니다.

목차

매개변수

a - 사용할 할당자
n - 저장 공간을 할당할 객체의 수
hint - 인접 메모리 위치에 대한 포인터

반환값

a. allocate ( n ) 호출에 의해 반환된 포인터.

참고 사항

Alloc::allocate P0593R6 이전까지 배열 객체를 생성할 필요가 없었습니다. 해당 표준안은 코어 언어 명세의 엄격한 해석에 따르면 std::vector 및 일부 다른 컨테이너들에 대해 기본이 아닌 할당자를 사용하는 것이 명확히 정의되지 않았던 문제를 해결했습니다.

allocate 를 호출한 후 요소들의 생성 전에, Alloc :: value_type * 의 포인터 연산은 할당된 배열 내에서 잘 정의되지만, 요소들이 접근될 경우 그 동작은 정의되지 않습니다.

예제

참고 항목

초기화되지 않은 저장 공간을 할당합니다
( std::allocator<T> 의 public 멤버 함수)