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

前端 未结 9 1513
-上瘾入骨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:33

    Because the array to be 'deleted' should have been created with a single use of the 'new' operator. The 'new' operation should have put that information on the heap. Otherwise, how would additional uses of new know where the heap ends?

提交回复
热议问题