how does the compiler, running program ? know how much memory to delete with the delete[] because if there is no reference to the size that the developer can access, is it the compiler that tell the delete[] operator how much to delete ? or is it within the running program.. thus why cannot the developer access that size element as such ?

or does the delete[] just delete objects that are of that type until it stops ? or is there a end point attached to the new creation ?

The size of the allocated chunk of memory is usually stored somewhere, but that is not required and completely depends on the implementation. Imagine a specialized memory management that exclusively sets aside a few pages of memory for allocations of exactly 4 bytes. In that case the size doesn't need to be stored.

Even if there was an uniform way of accessing the allocation size, it wouldn't be necessary.

> how does the compiler, running program ? know how much memory to delete
There is a lot of plumbing behind new that manages info like how many bytes are in an assigned block. delete uses that info to free the block.

> why cannot the developer access that size element as such ?
It was probably not an important enough feature, or too complex for some platforms to implement without adding a lot of overhead to allocations that would not use the feature. The developer can pass around the size, or wrap the size along with the pointer in a class, so it is not a critical thing.

thanks for the answers, I suppose it comes back to the c++ idea, of the software develop is the person in control as such.

thanks

This article has been dead for over six months. Start a new discussion instead.