c++ - Why in VC, both 'delete' and 'delete []' uses scalar deleting destructor? -


in understanding c++ memory model, when object array created new[], , deleted 'delete []', scalar constructor/destructor used, , compiler generates internal loop iterate every element location.

int main() {     b obj;     b* pb = new b;//no scalar constructor     delete pb;//scalar deleting destructor } 

but found when use 'new' 'delete' operate 1 element, without using '[]', vc still generates code 'scalar deleting descturctor' debug version.

so question is:

  1. scalar constructor/destructor don't have appearing in pair, right? in test program, found there's scalar deleting destructor.
  2. all objects created new or new[], should have scalar deleting destructor? why 1 element still have consideration, don't see necessity 1 element's case process exception, stack unwinding, should rely on deleting destructor. reasons?

  1. scalar constructor/destructor don't have appearing in pair, right? in test program, found there's scalar deleting destructor.

i wrong don't think there on constructor side analogous scalar deleting destructor.

  1. all objects created new or new[], should have scalar deleting destructor? why 1 element still have consideration, don't see necessity 1 element's case process exception, stack unwinding, should rely on deleting destructor. reasons?

delete ptr calls scalar deleting destructor.
delete [] ptr calls vector deleting destructor.

a answer found @ http://www.pcreview.co.uk/threads/scalar-deleting-destructor.1428390/.

it's name that's reported helper function vc writes every class destructor. "scalar deleting destructor" class equivalent to:

void scalar_deleting_destructor(a* pa) {    pa->~a();    a::operator delete(pa); } 

there's sister function that's generated, called 'vector deleting destructor'. looks like:

void vector_deleting_destructor(a* pa, size_t count) {    (size_t = 0; < count; ++i)       pa.~a();    a::operator delete[](pa); } 

Comments

Post a Comment