memory_allocation_result

memory_allocation_result (std::allocation_result)

<memory> 헤더에 정의되어 있어요. 적절한 Allocator 타입의 allocate_at_least 멤버 함수와 std::allocator_traits::allocate_at_least에서 반환되는 결과 타입이에요. C++23부터 도입됐어요.

출처: cppreference

본문

template< class Pointer, class SizeType = std::size_t >
struct allocation_result;

(C++23부터)

allocation_result 특수화는 적절한 Allocator 타입(예: std::allocator::allocate_at_least)의 allocate_at_least 멤버 함수와 std::allocator_traits::allocate_at_least에서 반환돼요.

모든 allocation_result 특수화는 ptrcount 외에는 기반 클래스나 선언된 멤버가 없어서, 애그리게이트 초기화와 구조적 바인딩(structured binding)에 적합해요.

템플릿 매개변수

  • Pointer: 일반적으로 std::allocator_traits<Alloc>::pointer (Alloc는 Allocator 타입)
  • SizeType: 일반적으로 std::allocator_traits<Alloc>::size_type (Alloc는 Allocator 타입)

데이터 멤버

  • ptr: Pointer 타입의 포인터. 일반적으로 할당된 저장 공간의 첫 요소 주소로 쓰여요.
  • count: 할당된 저장 공간의 요소 수를 담는 SizeType 타입 값.

allocate_at_least는 요청한 개수 이상을 할당할 수 있도록 설계되어, 실제 할당된 개수를 count로 돌려줘요. 호출자는 count만큼 요소를 안전하게 사용할 수 있어요.

auto [p, n] = alloc.allocate_at_least(10);  // p: 포인터, n: 실제 할당 개수

더 알아보기 (Learn more)

cppreference