Boost.Pool: различия между версиями

Содержимое удалено Содержимое добавлено
Строка 438:
* [5.3.4/10] (Expressions::Unary expressions::New) "... For arrays of char and unsigned char, the difference between the result of the new-expression and the address returned by the allocation function shall be an integral multiple of the most stringent alignment requirement (3.9) of any object type whose size is no greater than the size of the array being created. [Note: Because allocation functions are assumed to return pointers to storage that is appropriately aligned for objects of any type, this constraint on array allocation overhead permits the common idiom of allocating character arrays into which objects of other types will later be placed."
* [5.3.4/10] (Выражения::Унарные выражения::New) "... Для массивов типов char и unsigned char, разница между результатом new-выражения и адресом, возвращаемом функцией выделения должен быть shall be an integral multiple of the most stringent alignment requirement (3.9) of any object type whose size is no greater than the size of the array being created. [Note: Because allocation functions are assumed to return pointers to storage that is appropriately aligned for objects of any type, this constraint on array allocation overhead permits the common idiom of allocating character arrays into which objects of other types will later be placed."
=====''ConsiderВозьмем: imaginaryвоображаемый objectобъект typeтипа Element, ofразмер aкоторого sizeкратен whichразмеру isкакого-либо aнастоящего multipleобъекта; of some actual object size;принимаем, assumeчто sizeof(Element) > POD_size''=====
 
Обратите внимание, что существование объекта такого размера допустимо. Один объект такого размера представляет собой массив "настоящих" объектов.
 
Обратите внимание, что блок правильно выравнен для Element. Это напрямую вытекает из ПредикатаУтверждения 2.
 
Заключение 1: Блок правильно выравнен для массива из Elements
Corollary 1: The block is properly aligned for an array of Elements
 
Это следует из Утверждений 1 и 2, и следующей цитаты:
This follows from Predicates 1 and 2, and the following quote:
 
[3.9/9] (Basic concepts::Types) "An object type is a (possibly cv-qualified) type that is not a function type, not a reference type, and not a void type." <br />
[3.9/9] (Основные концепции::Типы) "Объектный тип является (возможно cv-qualified) типом, не являющимся функциональным типом, ссылочным типом, или типом void." <br />
 
(Конкретнее, типы массивов являются объектными типами)
(Specifically, array types are object types.)
 
Заключение 2: Для любого указателя p и целого i, если p правильно выравнен в соответствии с типом, на который он указывает, то p + i (when well-defined) также правильно выравнено для этого типа; другими словами, если массив имеет правильное выравнивание, то каждый элемент в этом массиве имеет правильное выравнивание
Corollary 2: For any pointer p and integer i, if p is properly aligned for the type it points to, then p + i (when well-defined) is properly aligned for that type; in other words, if an array is properly aligned, then each element in that array is properly aligned
 
Нет цитат из Стандарта прямо подтверждающих данное утверждение, но это соответствует общей концепции понятия "выравнивание".
There are no quotes from the Standard to directly support this argument, but it fits the common conception of the meaning of "alignment".
 
NoteОбратите thatвнимание, theчто conditionsусловие forдля p + i beingбыть well-defined обрисовано(are outlined) inв [5.7/5]. WeМы doне notцитируем quoteэто that hereздесь, butа onlyтолько makeобращаем noteвнимание thatна itто, isчто (p + i) является well-defined ifесли p andи p + i оба указывают в один и тот же массив или на следующий элемент за массивом(?) (both point into or one past the same array).
 
LetПусть: sizeof(Element) beявляется theнаименьшим leastобщим commonмножителем multipleразмеров ofнескольких sizesреальных of several actual objectsобъектов (T1, T2, T3, ...)
 
LetПусть: blockблок beбудет aуказателем pointerна toблок the memory blockпамяти, pe be будет(Element *) blockблоком, andи pn beбудет (Tn *) blockблок
 
CorollaryЗаключение 3: ForДля eachкаждого integerцелого i, suchтакого thatчто pe + i isявляется well-defined, thenтогда forдля eachкаждого n, thereсуществует exists some integerцелое jn suchтакое thatчто pn + jn isявляется well-defined andи ссылается refersна toтот theже sameадрес memoryпамяти addressчто asи pe + i
 
This follows naturally, since the memory block is an array of Elements, and for each n, sizeof(Element) % sizeof(Tn) == 0; thus, the boundary of each element in the array of Elements is also a boundary of each element in each array of Tn.