<div class="t-tr-text">оператора<div class="t-tr-dropdown"><div><div><div class="t-tr-dropdown-arrow-border"></div><div class="t-tr-dropdown-arrow"></div><div class="t-tr-dropdown-h">Original:</div><div class="t-tr-dropdown-orig">operator</div><div class="t-tr-dropdown-notes">The text has been machine-translated via [http://translate.google.com Google Translate].<br/> You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.</div></div></div></div></div> new<div class="t-tr-text">, Оператор<div class="t-tr-dropdown"><div><div><div class="t-tr-dropdown-arrow-border"></div><div class="t-tr-dropdown-arrow"></div><div class="t-tr-dropdown-h">Original:</div><div class="t-tr-dropdown-orig">, operator</div><div class="t-tr-dropdown-notes">The text has been machine-translated via [http://translate.google.com Google Translate].<br/> You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.</div></div></div></div></div> new[]
Материал из cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Заголовочный файл <new>
|
||
| void* operator new ( std::size_t count ); |
(1) | |
| void* operator new[]( std::size_t count ); |
(2) | |
| void* operator new ( std::size_t count, const std::nothrow_t& ); |
(3) | |
| void* operator new[]( std::size_t count, const std::nothrow_t& ); |
(4) | |
| void* operator new ( std::size_t, void* ptr ); |
(5) | |
| void* operator new[]( std::size_t, void* ptr ); |
(6) | |
Выделяет запрошенное количество байт. Эти распределения функции вызываются новых выражений для выделения памяти, в которой новый объект затем будет инициализирован.
1-2) Original:
Allocates requested number of bytes. These allocation functions are called by новых выражений to allocate memory in which new object would then be initialized.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Выделяет
3-4) count байт из бесплатных магазине. Вызывает функцию указатель, возвращенный std::get_new_handler в случае неудачи и повторяет распределение попытки до тех пор пока новый обработчик не возвращается, либо становится пустой указатель, на котором бросает std::bad_alloc.Original:
Allocates
count bytes from free store. Calls the function pointer returned by std::get_new_handler on failure and repeats allocation attempts until new handler does not return or becomes a null pointer, at which time throws std::bad_alloc.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
То же, что 1-2, но возвращает пустой указатель, когда 1-2 бросит std::bad_alloc
5-6) Original:
Same as 1-2, but returns a null pointer when 1-2 would throw std::bad_alloc
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
ничего не делает, возвращается
ptr. Эти версии называется новое выражение, которое строится объектов в ранее выделенных хранения.Original:
does nothing, returns
ptr. These versions are called by new-expression which construct objects in previously allocated storage.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Содержание |
[править] Замена и перегрузки
Версий 1-4) неявно объявленный в каждой единице трансляции, даже если
<new> заголовок не включается. Эти функции' сменный: предоставленные пользователями, не являющимися членами функции с той же подписью заменяет неявное версии. В более одной замены могут быть предоставлены для каждой из четырех неявной функции распределения. Кроме того, программа может определить класс версий членов этих функций или определить распределение функций с различными подписями (кроме того, что он не допускается замена (5-6) версии распределение функций). Добавить подпись должна выглядеть следующим образом, где count это количество байт для распределения и' placement_params являются параметры подаваемого в new выражение:Original:
The versions 1-4) are implicitly declared in each translation unit even if the
<new> header is not included. These functions are replaceable: a user-provided non-member function with the same signature replaces the implicit version. At most one replacement may be provided for each of the four implicit allocation functions. Also, program can define class member versions of these functions or define allocation functions with different signatures (except that it is not permitted to replace (5-6) versions of the allocation function). The added signature should look like the following, where count is number of bytes to allocate and placement_params are the parameters supplied to the new expression:The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
| void* operator new (size_t count/*, placement_params*/); |
for the new version |
|
| void* operator new[](size_t count/*, placement_params*/); |
for the new[] version |
|
Распределение функций может быть заменен / перегруженный двумя способами:
Original:
The allocation function can be replaced/overloaded in two ways:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
- 'В глобальном масштабе': для того, чтобы называть его, подпись перегруженные функции распределения должны быть видны на место распределения, за исключением неявно объявленные функции распределения по умолчанию. Такое распределение функций будет использоваться для всех ассигнований с соответствующими параметрами в текущей программеOriginal:in the global scope: in order to call it, the signature of the overloaded allocation functions must be visible at the place of allocation, except for implicitly declared default allocation functions. This allocation function will be used for all allocations with corresponding parameters in the current programThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 'В локальной области': перегруженные
operator newдолжны быть статическими общественные функции члена класса. Такое распределение функций будет использоваться только на приобретение данного класса.Original:in the local scope: the overloadedoperator newmust be static public member function of the class. This allocation function will be used only for allocations of that particular class.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Во время компиляции, каждый
new выражением смотрит на название соответствующей функции распределения в первую очередь в области видимости класса, и после этого в глобальном масштабе. Это может быть проинструктированы, чтобы пропустить первый шаг по телефону new как ::new. Обратите внимание, что в соответствии с перегрузке правил, любое распределение функций, объявленных в классе сферу скрывает все глобальные функции распределения. Для получения дополнительной информации см. NJ выражение. Отметим, что это не возможно разместить распределение функций в пространстве имен.Original:
During compilation, each
new expression looks up for appropriate allocation function's name firstly in the class scope and after that in the global scope. It can be instructed to skip the first step by calling new as ::new. Note, that as per перегрузке правил, any allocation functions declared in class scope hides all global allocation functions. For more information see NJ выражение. Note, that it is not possible to place allocation function in a namespace.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[править] Параметры
| count | - | количество байт для распределения
Original: number of bytes to allocate The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| ptr | - | Указатель на область памяти для инициализации объекта в
Original: pointer to a memory area to initialize the object at The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[править] Возвращаемое значение
1-4)указатель на выделенную область памяти
Original:
pointer to allocated memory area
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
5-6) ptr
[править] Исключения
1-2)бросает std::bad_alloc о невозможности выделить память
3-6)
Original:
throws std::bad_alloc on failure to allocate memory
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[править] См. также
| освобождение функций Original: deallocation functions The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (функция) | |
| (C++11) |
получает текущую новый обработчик Original: obtains the current new handler The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (функция) |
| регистрирует новый обработчик Original: registers a new handler The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (функция) | |
| получает неинициализированные хранения Original: obtains uninitialized storage The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (функция) | |
| выделяет память Original: allocates memory The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (функция) | |