Why is it not possible to get the length of a buffer allocated in this fashion.
AType * pArr = new AType[nVariable];
When the same array is deallocated
delete [] pArr;
the runtime must know how much to deallocate. Is there any means to access the length before deleting the array. If no, why no such API is provided that will fetch the length?
The
delete
operator doesn't need to know the size to free the allocated memory, just like thefree
system call doesn't. This is because that problem is left to the operating system and not the compilers runtime system.