X-Originating-IP: [208.160.246.197] From: "Nimrod Abing" To: djgpp AT delorie DOT com Subject: Re: strdup() with delete[] Date: Mon, 11 Sep 2000 18:49:04 PHT Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 11 Sep 2000 10:49:04.0906 (UTC) FILETIME=[E752CEA0:01C01BDD] Reply-To: djgpp AT delorie DOT com >From: manni DOT heumann AT gmx DOT de (Manni Heumann) >Reply-To: djgpp AT delorie DOT com >To: djgpp AT delorie DOT com >Subject: Re: strdup() with delete[] >Date: Mon, 11 Sep 2000 09:12:39 GMT > > > > >I guess the [] form is considered obsolete. I would use simple delete s. delete [] obj_ptr is not obsolete. It is _the_proper_ way to deallocate an array of objects. What is obsolete is delete [nn] obj_ptr, where NN would be the number of objects that were allocated for the array. > >The operator's implementation knows how many objects are allocated. > > This is a fatal assumption, unless you create an `allocator' class that would manage the free memory pool, which is the case with the vector and similar STL container classes. Anyway, I prefer using STL over hand written code. It saves me hours of coding unnecessary code. The `vector' class is very versatile when you want arrays of things. Overloading delete is different from delete [] as well, and if this is not an indication that the two are very distinct forms of the same operator, then I don't know what is. >Wow! Obsolete. Try this and then tell us whether it is obsolete: > >class Test { >public: > Test () { cout << "Constructing\n"; } > ~Test () { cout << "Destructing\n"; } >}; > >int main () { > Test *t = new Test [3]; > delete t; In a real world scenario, this would be a fatal mistake since the destructor would only be called for t[0]. The correct form would be: delete [] t; > return 0; >} > >-- > >Manni > >"Life would be much easier if I had the source code." You said it! :-D ---------------- _nimrod_a_abing_ +----------------------------------------------------+ |Homepage: http://www.geocities.com/n_abing/index.htm| +----------------------------------------------------+ _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. Share information about yourself, create your own public profile at http://profiles.msn.com.