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."
=====''
Обратите внимание, что существование объекта такого размера допустимо. Один объект такого размера представляет собой массив "настоящих" объектов.
Обратите внимание, что блок правильно выравнен для Element. Это напрямую вытекает из
Заключение 1: Блок правильно выравнен для массива из Elements
Это следует из Утверждений 1 и 2, и следующей цитаты:
[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 />
(Конкретнее, типы массивов являются объектными типами)
Заключение 2: Для любого указателя p и целого i, если p правильно выравнен в соответствии с типом, на который он указывает, то p + i (when well-defined) также правильно выравнено для этого типа; другими словами, если массив имеет правильное выравнивание, то каждый элемент в этом массиве имеет правильное выравнивание
Нет цитат из Стандарта прямо подтверждающих данное утверждение, но это соответствует общей концепции понятия "выравнивание".
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.
|