Концепции C++: Allocator
Материал из cppreference.com
|
|
Эта страница была переведена автоматически с английской версии вики используя Переводчик Google. Перевод может содержать ошибки и странные формулировки. Наведите курсор на текст, чтобы увидеть оригинал. Щёлкните здесь, чтобы увидеть английскую версию этой страницы. (Вы можете помочь в исправлении ошибок и улучшении перевода. Для инструкций перейдите по ссылке.) |
<metanoindex/>
Инкапсулирует выделения и освобождения памяти стратегии.
Оригинал:
Encapsulates memory allocation and deallocation strategy.
Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
Каждый стандартный компонент библиотеки, которые, возможно, потребуется выделить или освободить хранения, из
std::string, std::vector, и каждый контейнер, за исключением std::array, чтобы std::shared_ptr и std::function, делает это через Allocator: объект класса типа, который удовлетворяет следующим требованиям.Оригинал:
Every standard library component that may need to allocate or release storage, from
std::string, std::vector, and every container except std::array, to std::shared_ptr and std::function, does so through an Allocator: an object of a class type that satisfies the following requirements.Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
Некоторые требования являются обязательными: шаблон std::allocator_traits обеспечивает реализацию по умолчанию для всех системных требований, и все стандартные библиотеки контейнеров и других распределитель-классы, которые знают доступ к распределителю через
std::allocator_traits, а не напрямую.Оригинал:
Some requirements are optional: the template std::allocator_traits supplies the default implementations for all optional requirements, and all standard library containers and other allocator-aware classes access the allocator through
std::allocator_traits, not directly.Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
Требования
Учитывая
Оригинал:
Given
Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
A, распределитель типаTОригинал:A, an Allocator for typeTТекст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.B, тот же распределитель типаUОригинал:B, the same Allocator for typeUТекст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.ptr, значение типаallocator_traits<A>::pointer, полученной через вызовallocator_traits<A>::allocate()Оригинал:ptr, a value of typeallocator_traits<A>::pointer, obtained by callingallocator_traits<A>::allocate()Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.cptr, значение типаallocator_traits<A>::const_pointer, полученной по конверсии отptrОригинал:cptr, a value of typeallocator_traits<A>::const_pointer, obtained by conversion fromptrТекст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.vptr, значение типаallocator_traits<A>::void_pointer, полученной по конверсии отptrОригинал:vptr, a value of typeallocator_traits<A>::void_pointer, obtained by conversion fromptrТекст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.cvptr, значение типаallocator_traits<A>::const_void_pointer, полученной по конверсии отcptrилиvptrОригинал:cvptr, a value of typeallocator_traits<A>::const_void_pointer, obtained by conversion fromcptror fromvptrТекст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.xptr, dereferencable указатель на некоторый типXОригинал:xptr, a dereferencable pointer to some typeXТекст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
| Expression | Requirements | Return type |
|---|---|---|
A::pointer (необязательным)
|
Satisfies NullablePointer and RandomAccessIterator
|
|
A::const_pointer (необязательным)
|
A::pointer is convertible to A::const_pointer. Satisfies NullablePointer and RandomAccessIterator
|
|
A::void_pointer (необязательным)
|
A::pointer is convertible to A::void_pointer
B::void_pointer и A::void_pointer того же типа. Удовлетворяет NullablePointerОригинал: Текст был переведён автоматически используя Переводчик Google. Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда. |
|
A::const_void_pointer (необязательным)
|
A::pointer, A::const_pointer, and A::void_pointer are convertible to A::const_void_pointer
B::const_void_pointer и A::const_void_pointer того же типа. Удовлетворяет NullablePointerОригинал: Текст был переведён автоматически используя Переводчик Google. Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда. |
|
A::value_type
|
the type T
| |
A::size_type (необязательным)
|
A::size_type can represent the size of the largest object A can allocate
|
unsigned integer type |
A::difference_type (необязательным)
|
A::difference_type can represent the difference of any two pointers to the objects allocated by A
|
signed integer type |
A::template rebind<U>::other (дополнительно [1])
|
for any U, B::template rebind<T>::other is A
|
the type B
|
*ptr
|
T&
| |
*cptr
|
*cptr and *ptr identify the same object
|
const T&
|
ptr->m
|
same as (*ptr).m, if (*ptr).m is well-defined
|
the type of T::m
|
cptr->m
|
same as (*cptr).m, if (*cptr).m is well-defined
|
the type of T::m
|
static_cast<A::pointer>(vptr)
|
static_cast<A::pointer>(vptr) == ptr
|
A::pointer
|
static_cast<A::const_pointer>(cvptr)
|
static_cast<A::const_pointer>(vptr) == cptr
|
A::const_pointer
|
a.allocate(n)
|
allocates storage suitable for n objects of type T, but does not construct them. May throw exceptions.
|
A::pointer
|
a.allocate(n, cptr) (необязательным)
|
same as a.allocate(n), but may use cptr in unspecified manner to aid locality
|
A::pointer
|
a.deallocate(ptr, n)
|
deallocates storage previously allocated by a call to a.allocate(n). Does not call destructors, if any objects were constructed, they must be destroyed before calling a.deallocate(). Does not throw exceptions.
|
(not used) |
a.max_size() (необязательным)
|
the largest value that can be passed to A::allocate()
|
A::size_type
|
a1 == a2
|
returns true only if the storage allocated by the allocator a1 can be deallocated through a2. Establishes reflexive, symmetric, and transitive relationship. Does not throw exceptions.
|
bool
|
a1 != a2
|
same as !(a1==a2)
|
bool
|
A a1(a)
|
Copy-constructs a1 such that a1 == a. Does not throw exceptions.
|
|
A a(b)
|
Constructs a such that B(a)==b and A(b)==a. Does not throw exceptions.
|
|
A a1(std::move(a))
|
Constructs a1 such that it equals the prior value of a. Does not throw exceptions.
|
|
A a(std::move(b))
|
Constructs a such that it equals the prior value of A(b). Does not throw exceptions.
|
|
a.construct(xptr, args) (необязательным)
|
Constructs an object of type X in previously-allocated storage at the address pointed to by xptr, using args as the constructor arguments
|
|
a.destroy(xptr) (необязательным)
|
Destructs an object of type X pointed to by xptr, but does not deallocate any storage.
|
|
a.select_on_container_copy_construction() (необязательным)
|
Provides an instance of A to be used by the container that is copy-constructed from the one that uses a currently. Usually returns either a copy of a or a default-constructed A().
|
A
|
a.propagate_on_container_copy_assignment (необязательным)
|
true if the allocator of type A needs to be copied when the container that uses it is copy-assigned
|
std::true_type or std::false_type or derived from such |
a.propagate_on_container_move_assignment (необязательным)
|
true if the allocator of type A needs to be copied when the container that uses it is move-assigned
|
std::true_type or std::false_type or derived from such |
a.propagate_on_container_swap (необязательным)
|
true if the allocators of type A need to be swapped when two containers that use them are swapped
|
std::true_type or std::false_type or derived from such |
Примечания:
Оригинал:
Notes:
Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
[1] перепривязывают только дополнительный (при условии, STD :: allocator_traits), если это распределитель является шаблоном формы SomeAllocator <T, Args>, где Args равна нулю или несколько дополнительных параметров шаблона.
Оригинал:
[1] rebind is only optional (provided by std::allocator_traits) if this allocator is a template of the form SomeAllocator<T, Args>, where Args is zero or more additional template parameters.
Текст был переведён автоматически используя Переводчик Google.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.
Вы можете проверить и исправить перевод. Для инструкций щёлкните сюда.