Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete vs destroy

Status
Not open for further replies.

Prattaratt

Technical User
Aug 6, 2000
291
US
I recently DL'd source code for Borland's ancient Turbo Vision framework. However, some of the source contains the line:
destroy (objptr);
The only documentation I've been able to come across on the destroy functoin was an obscure and not helpful reference in my MSVC6.0(Introductory Version) help files, which basically says that the destroy function will call the objptr's destructor??? I thought that happened when the object was deleted. Any clarification? Can I change those lines to read:
delete objptr;
without worry or is there more to the destroy function?

 
The destroy does call the destructor routine, it's obscure and a way to control an object. It could however be used to control dynamic objects by the next upper software-layer.

It could be that it's used to ensure that an object really is destroyed, there might be certain conditions which skips the destructor which should be run per default, thus a "manual" destroy is done. Speculations: yes, but it's my best guess.

How to do is hard to say but my guess is to call the destroyer:
destroy (objptr); // transforms
objptr->~objptr(); // to this though it might be wrong syntax.

In theory the
delete objptr;
should do the trick too. Give it a try.

Totte
Keep making it perfect and it will end up broken.
 
The code in question involves the destruction of a list. Could it be that destroy also deletes objects contained in the list, where delete won't? HMM!
So if this an accepted function within the realm of C++, why is BCC 5.5 choking on it as an undeclared function? Is there an include file that needs to be designated for this particular function; if so which one?
 
destroy is not Standard C or C++. It must be specific to Turbo Vision's compiler or library.

The only thing I can think of is that destroy might call the object's destructor, but not free the memory allocated to it. This might be useful if you allocated the memory for an object, then constructed it into that memory with placement new. Deleting the object would try to free that memory, and it was never allocated by new.

Typically, though, in that case, you'd just explicitly call the destructor on the object.

i.e.
Code:
ptrToObj->~ObjectType()

If it looks like that's what the original code is attempting to do, you can try replacing the calls to destroy with explicit destructor calls.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top