How does delete[] “know” the size of the operand array?

前端 未结 9 1511
-上瘾入骨i
-上瘾入骨i 2020-11-22 02:50
Foo* set = new Foo[100];
// ...
delete [] set;

You don\'t pass the array\'s boundaries to delete[]. But where is that information stor

9条回答
  •  遥遥无期
    2020-11-22 03:18

    It is not standardized. In Microsoft's runtime the new operator uses malloc() and the delete operator uses free(). So, in this setting your question is equivalent to the following: How does free() know the size of the block?

    There is some bookkeeping going on behind the scenes, i.e. in the C runtime.

提交回复
热议问题