delete [] query

Well, I am not sure why don't we specify the size in delete operator? I know compiler finds it out after we allocate memory using new, but just want to know how it does it? I mean the internal implementation.

int* p = new int[5];
delete [] p //no size is mentioned.

Thanks in advance :)
I think the source code is included, at least with Visual Studio. Simply debug.

In general, the new operator writes the amount of data allocated just before the pointed location. That's what I heard last.
The size of an array is stored in run-time data. Internaly, when you declare int foo[n]; or int* foo=new int[n];, somewhere the compiler stores data: "array foo has n members". I don't know excatly how, but I know it does. Another example is that you can make a temlate function that has the template parameter thenumber of elements, and real parameter is a reverence to an array, and you can call it implicitly, without delaring the no. of elements, and it will know it! http://www.cplusplus.com/articles/D4SGz8AR/
Thanks all for the replies :)
@guestgulkan - The link is quite useful. Thanks :)
Topic archived. No new replies allowed.