Namespaces
Variants

std::allocator_traits<Alloc>:: allocate_at_least

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)
static constexpr std:: allocation_result < pointer, size_type >
allocate_at_least ( Alloc & a, size_type n ) ;
(C++23부터)

allocate_at_least a. allocate_at_least ( n ) 를 호출하고 호출이 형식에 맞는 경우 그 결과를 반환하며, 그렇지 않으면 return { a. allocate ( n ) , n } ; 와 동등합니다.

allocator_at_least 는 최소 n value_type 객체들을 위한 저장 공간을 할당하려 시도하며, 정확히 n 개의 객체를 위한 저장 공간을 할당하는 폴백(fallback) 메커니즘을 제공합니다.

목차

매개변수

a - 스토리지 할당에 사용되는 할당자
n - 스토리지를 할당할 객체 수의 하한

반환값

a. allocate_at_least ( n ) 해당 표현이 형식에 맞는 경우.

그렇지 않으면, std:: allocation_result < pointer, size_type > { a. allocate ( n ) , n } .

예외

선택된 할당 함수가 무엇을 언제 던지는지 설명합니다.

참고 사항

Allocator 타입의 allocate_at_least 멤버 함수는 주로 연속 컨테이너(예: std::vector std::basic_string )를 위해 제공되며, 가능한 경우 컨테이너의 용량이 실제 할당된 크기와 일치하도록 하여 재할당을 줄이는 것을 목적으로 합니다. allocate_at_least 는 폴백 메커니즘을 제공하므로 적절한 상황에서 직접 사용할 수 있습니다.

할당자 객체 a Alloc 타입일 때, result std:: allocator_traits < Alloc > :: allocate_at_least ( a, n ) 에서 반환된 값이라고 하면, 메모리 누수를 피하기 위해 저장 공간은 a. deallocate ( result. ptr , m ) (일반적으로 std:: allocator_traits < Alloc > :: deallocate ( a, result. ptr , m ) 를 통해 호출됨)로 해제되어야 합니다.

할당 해제에 사용되는 인수 m n 보다 작지 않고 result. count 보다 크지 않아야 하며, 그렇지 않으면 동작이 정의되지 않습니다. 할당자가 allocate_at_least 를 제공하지 않는 경우 n 은 항상 result. count 와 같다는 점에 유의하십시오. 이는 m n 과 같아야 함을 의미합니다.

기능 테스트 매크로 표준 기능
__cpp_lib_allocate_at_least 202302L (C++23) allocate_at_least

예제

참고 항목

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