I remember in C++, when a dynamic array is allocated, the size of this array is stored right before the array in memory. Therefore compiler knows exactly how long, when this array is deleted.
Do all compilers store the size this way? Is it a safe method to get the size of a dynamic array?
Here is a example code, it works fine on Visual Studio 2012.
I do not advice to use such a trick because the C++ standard does not specify how the implementation shall allocate a memory. Moreover some applications can use a user-defined scheme for memory allocation.