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

Содержимое удалено Содержимое добавлено
Строка 423:
Каждый блок памяти выделяется как POD тип (конкретно, как массив символов) с помощью оператора new[]. Возьмем POD_size как число выделенных символов.
 
=====''Утверждение 1: Массив не может иметь заполнения(padding).''=====
 
Это следует из следующей цитаты:
Строка 431:
Поэтому, массивы не могут содержать заполнение, но элементы внутри массивов могут.
 
=====''Утверждение 2: Любой блок памяти, выделенный как массив символов с помощью оператора new[] (здесь и далее - блок), имеет правильное выравнивание для любого объекта такого же или меньшего размера.''=====
 
Вытекает из:
Строка 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''=====
 
Note that an object of that size can exist. One object of that size is an array of the "actual" objects.