Namespaces
Variants

std::pmr::polymorphic_allocator<T>:: allocate_object

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)
template < class U >
U * allocate_object ( std:: size_t n = 1 ) ;
(C++20부터)

기본 메모리 리소스를 사용하여 n 개의 U 타입 객체에 대한 저장 공간을 할당합니다.

만약 std:: numeric_limits < std:: size_t > :: max ( ) / sizeof ( U ) < n 인 경우, std::bad_array_new_length 를 발생시키고, 그렇지 않으면 return static_cast < U * > ( allocate_bytes ( n * sizeof ( U ) , alignof ( U ) ) ) ; 와 동등합니다.

목차

매개변수

n - 저장 공간을 할당할 객체의 개수

반환값

할당된 저장소에 대한 포인터.

참고 사항

이 함수는 완전 특수화된 할당자 std:: pmr :: polymorphic_allocator <> 와 함께 사용하기 위해 도입되었지만, std:: pmr :: polymorphic_allocator < T > 에서 std:: pmr :: polymorphic_allocator < U > 로의 재바인딩을 피하기 위한 단축키로 어떤 특수화에서도 유용할 수 있습니다.

U 가 추론되지 않으므로, 이 함수를 호출할 때 템플릿 인자로 제공해야 합니다.

예외

std::bad_array_new_length 을 던집니다, 만약 n > std:: numeric_limits < std:: size_t > :: max ( ) / sizeof ( U ) 인 경우; 또한 resource ( ) - > allocate 호출에서 발생하는 모든 예외도 던질 수 있습니다.

참고 항목

기본 리소스에서 정렬된 원시 메모리를 할당합니다
(public member function)
(C++20)
객체를 할당하고 생성합니다
(public member function)
메모리를 할당합니다
(public member function)
[static]
할당자를 사용하여 초기화되지 않은 저장 공간을 할당합니다
( std::allocator_traits<Alloc> 의 public static member function)
메모리를 할당합니다
( std::pmr::memory_resource 의 public member function)