I came across this kind of code once in a while – I suspect the creator is/was afraid that table delete would iterate over the table and ‘cost performance’ (which imho will not be done either way)… is there any real benefit one might get/consider/imagine from not using the the table delete here?
myClass** table = new myClass* [size]; ... //some code that does not reallocate or change the value of the table pointer ;) delete table; // no [] intentionally
There’s really no reason to write like that and a serious reason to never do so.
It’s true that for types with trivial destructors (like raw pointers in your case) there’s no need to know the actual number of elements in the array and so the compiler might decide to map new[] and delete[] onto new and delete to reduce the overhead. If it decides this way you can’t stop it without extra steps taken, so this compiler optimization will take place without your notice and will be free.
At the same time someone using your code might wish to overload the global operators new and delete (and new[] and delete[] as well). If that happens you run into big trouble because this is when you may really need the difference between the delete and delete[].
Add to this that this compiler-dependent optimization is unportable.
So this is the case when you get no benefits displacing delete[] with delete but risk big time relying into undefined behaviour.