Edited by:
Since delete [] requires calling destructors for all elements of the array, the length must be saved somewhere. Due to why this memory is not available to prevent errors such as walking outside the array due to an unknown size - I'm not sure. Strictly speaking, the length of statically allocated arrays should be known at compile time, and the length of dynamically allocated arrays should be kept at runtime, therefore, in both cases, buffer overflow errors are theoretically prevented by 100%, but both static and dynamic arrays are unsafe . I assume this is for performance, border checking will make it slower, and the original (C-style) arrays provide better performance with zero security.
The implementation of this depends on the compiler and runtime providers; there may be some implementations that may be available and usable, but this will not be considered standard and recommended practice. The logical place for the stored length is somewhere in the header of the allocated memory fragment to the actual address that you will receive for the first element of the array.
dtech source share