Namespaces
Variants

std:: scoped_allocator_adaptor

From cppreference.net
Memory management library
( exposition only* )
Allocators
scoped_allocator_adaptor
(C++11)
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)
헤더에 정의됨 <scoped_allocator>
template < class OuterAlloc, class ... InnerAllocs >

class scoped_allocator_adaptor

: public OuterAlloc ;
(C++11부터)

std::scoped_allocator_adaptor 클래스 템플릿은 다중 레벨 컨테이너(맵의 튜플의 리스트의 집합의 벡터 등)와 함께 사용할 수 있는 할당자입니다. 이는 하나의 외부 할당자 타입 OuterAlloc 과 0개 이상의 내부 할당자 타입 InnerAlloc... 으로 인스턴스화됩니다. scoped_allocator_adaptor 로 직접 생성된 컨테이너는 해당 요소를 할당하기 위해 OuterAlloc 을 사용하지만, 요소 자체가 컨테이너인 경우 첫 번째 내부 할당자를 사용합니다. 해당 컨테이너의 요소들이 다시 컨테이너인 경우 두 번째 내부 할당자를 사용하는 방식으로 계속됩니다. 컨테이너의 레벨이 내부 할당자의 수보다 많은 경우, 마지막 내부 할당자가 모든 추가 중첩 컨테이너에 재사용됩니다.

이 어댑터의 목적은 중첩된 컨테이너에서 상태를 가지는 할당자를 올바르게 초기화하는 것입니다. 예를 들어, 중첩된 컨테이너의 모든 계층이 동일한 공유 메모리 세그먼트에 배치되어야 하는 경우에 사용됩니다. 어댑터의 생성자는 목록 내 모든 할당자에 대한 인수를 받으며, 각 중첩 컨테이너는 필요에 따라 어댑터로부터 자신의 할당자 상태를 획득합니다.

scoped_allocator_adaptor 의 목적 상, 다음 내부 할당자가 A 일 때, std:: uses_allocator < T,A > :: value == true 인 모든 클래스 T 는 마치 컨테이너인 것처럼 재귀에 참여합니다. 추가적으로, std::pair scoped_allocator_adaptor::construct 의 특정 오버로드에 의해 이러한 컨테이너로 취급됩니다.

일반적인 구현은 std::scoped_allocator_adaptor<InnerAllocs...> 인스턴스를 멤버 객체로 보유합니다.

std::pmr::polymorphic_allocator s 가 중첩 컨테이너로 전파되는 것은 uses-allocator construction 규칙을 따르며, std::scoped_allocator_adaptor 가 필요하지 않고(또한 함께 작동하지도 않음)에 주목하십시오.

목차

중첩 타입

유형 정의
outer_allocator_type OuterAlloc
inner_allocator_type
  • scoped_allocator_adaptor < OuterAlloc > 만약 sizeof... ( InnerAllocs ) 가 0인 경우
  • scoped_allocator_adaptor < InnerAllocs... > 그 외의 경우
value_type std:: allocator_traits < OuterAlloc > :: value_type
size_type std:: allocator_traits < OuterAlloc > :: size_type
difference_type std:: allocator_traits < OuterAlloc > :: difference_type
pointer std:: allocator_traits < OuterAlloc > :: pointer
const_pointer std:: allocator_traits < OuterAlloc > :: const_pointer
void_pointer std:: allocator_traits < OuterAlloc > :: void_pointer
const_void_pointer std:: allocator_traits < OuterAlloc > :: const_void_pointer


주어진 OuterAlloc InnerAlloc... 의 집합을 Allocs 로 합니다:

유형 정의
propagate_on_container_copy_assignment
propagate_on_container_move_assignment
propagate_on_container_swap
is_always_equal

멤버 함수

새로운 scoped_allocator_adaptor 객체를 생성함
(public member function)
scoped_allocator_adaptor 객체를 파괴함
(public member function)
scoped_allocator_adaptor 를 할당함
(public member function)
inner_allocator 참조를 얻음
(public member function)
outer_allocator 참조를 얻음
(public member function)
외부 할당자를 사용하여 초기화되지 않은 저장 공간을 할당함
(public member function)
외부 할당자를 사용하여 저장 공간을 해제함
(public member function)
외부 할당자가 지원하는 최대 할당 크기를 반환함
(public member function)
할당된 저장 공간에 객체를 생성하며, 적절한 경우 내부 할당자를 해당 생성자에 전달함
(public member function)
할당된 저장 공간의 객체를 파괴함
(public member function)
scoped_allocator_adaptor 와 모든 할당자의 상태를 복사함
(public member function)
설명 전용 함수 템플릿
최외곽 할당자를 얻음
( 설명 전용 멤버 함수* )
최외곽 할당자를 사용하여 객체를 생성함
( 설명 전용 멤버 함수* )
최외곽 할당자를 사용하여 객체를 파괴함
( 설명 전용 멤버 함수* )

비멤버 함수

(C++20에서 제거됨)
두 개의 scoped_allocator_adaptor 객체를 비교
(함수 템플릿)

추론 가이드 (C++17부터)

중첩 클래스

클래스 정의
rebind template < class T >

struct rebind
{
using other = scoped_allocator_adaptor
< std:: allocator_traits < OuterAlloc > :: template rebind_alloc < T > ,
InnerAllocs... > ;
} ;

예제

#include <boost/interprocess/allocators/adaptive_pool.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <scoped_allocator>
#include <vector>
namespace bi = boost::interprocess;
template<class T>
using alloc = bi::adaptive_pool<T, bi::managed_shared_memory::segment_manager>;
using ipc_row = std::vector<int, alloc<int>>;
using ipc_matrix = std::vector<ipc_row, std::scoped_allocator_adaptor<alloc<ipc_row>>>;
int main()
{
    bi::managed_shared_memory s(bi::create_only, "Demo", 65536);
    // 공유 메모리에서 벡터의 벡터 생성
    ipc_matrix v(s.get_segment_manager());
    // 모든 추가 작업에서 내부 벡터들은 할당자 인수를
    // 외부 벡터의 scoped_allocator_adaptor에서 얻음
    v.resize(1);
    v[0].push_back(1);
    v.emplace_back(2);
    std::vector<int> local_row = {1, 2, 3};
    v.emplace_back(local_row.begin(), local_row.end());
    bi::shared_memory_object::remove("Demo");
}

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 2108 C++11 scoped_allocator_adaptor 가 상태 비저장인지 확인할 방법이 없었음 is_always_equal 제공

참고 항목

할당자 타입에 대한 정보를 제공함
(클래스 템플릿)
지정된 타입이 uses-allocator 생성 방식을 지원하는지 확인함
(클래스 템플릿)
기본 할당자
(클래스 템플릿)