Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!rpi!image.soe.clarkson.edu!news From: cline@cheetah.ece.clarkson.edu (Marshall Cline) Newsgroups: comp.lang.c++ Subject: ``delete[]p'' -- where is the actual size of *p stored? Message-ID: Date: 21 Aug 90 17:47:29 GMT Sender: news@sun.soe.clarkson.edu Reply-To: cline@sun.soe.clarkson.edu (Marshall Cline) Distribution: comp Organization: (I don't speak for the) ECE Dept, Clarkson Univ, Potsdam, NY Lines: 39 `delete p' (where `p' is a pointer to a base class with a *virtual* dtor) ``does the right thing'' (calls the right dtor) based on the actual type of the object pointed to by `p'. But what if Derived is bigger than Base, and `p' points to a bunch of Derived's (ie: p = new Derived[100]). Will delete[] (or delete[100]) find the actual size of the pointed-to objects from the vtable? Or will it get this size from something hidden near *p itself? This information appears to be necessary in order to avoid messing ones pants... class B { //... public: //... virtual ~B(); }; class D : public B { int D_is_bigger_than_B; public: //... ~D(); }; main() { B* p = new D[100]; //... delete [] p; } -- ============================================================================== Marshall Cline / Asst.Prof / ECE Dept / Clarkson Univ / Potsdam, NY 13676 cline@sun.soe.clarkson.edu / Bitnet:BH0W@CLUTX / uunet!clutx.clarkson.edu!bh0w Voice: 315-268-3868 / Secretary: 315-268-6511 / FAX: 315-268-7600 Career search in progress; ECE faculty; research oriented; will send vita. PS: If your company is interested in on-site C++/OOD training, drop me a line! ==============================================================================