Array placement-new requires unspecified overhead in the buffer?

前端 未结 6 1288
甜味超标
甜味超标 2020-11-22 15:09

5.3.4 [expr.new] of the C++11 Feb draft gives the example:

new(2,f) T[5] results in a call of operator new[](sizeof(T)*5+

6条回答
  •  醉话见心
    2020-11-22 15:48

    This overhead may be applied in all array new-expressions, including those referencing the library function operator new[](std::size_t, void*) and other placement allocation functions.

    This is a defect in the standard. Rumor has it they couldn't find a volunteer to write an exception to it (Message #1173).

    The non-replaceable array placement-new cannot be used with delete[] expressions, so you need to loop through the array and call each destructor.

    The overhead is targetted at the user-defined array placement-new functions, which allocate memory just like the regular T* tp = new T[length]. Those are compatible with delete[], hence the overhead that carries the array length.

提交回复
热议问题