How does delete[] know the size of an array?

后端 未结 8 1149
面向向阳花
面向向阳花 2021-01-02 01:51

I am curious how delete[] figures out the size of the allocated memory. When I do something like:

int* table = new int[5];
delete[] table;

8条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-02 02:23

    My guess is that new[] actually allocates more data than it seems. It probably has a few bytes before the pointer that is returned that tells how many items are in the array.

提交回复
热议问题