destroy() / free / malloc

Everything related to the code /
Tout ce qui touche au code
Post Reply
milipili
Posts: 545
Joined: Thu Nov 02, 2006 8:52 am
Location: Paris (France)
Contact:

destroy() / free / malloc

Post by milipili » Sat Jun 07, 2008 4:19 pm

Could you explain me the interest of this kind of method :

Code: Select all

void destroy();
I assume it must be for some special goal but I don't see it.
Damien Gerard
Ta3d & Yuni Developer

User avatar
Balthazar
Moderator
Posts: 2055
Joined: Wed Nov 01, 2006 4:31 pm
Location: Russian Federation
Contact:

Post by Balthazar » Sat Jun 07, 2008 5:02 pm

Well, when you see this string you should count from 1 to 100 :)

User avatar
zuzuf
Administrateur - Site Admin
Posts: 3281
Joined: Mon Oct 30, 2006 8:49 pm
Location: Toulouse, France
Contact:

Post by zuzuf » Sat Jun 07, 2008 5:05 pm

the destroy() method cleans the object without removing it from memory, it may not free all the memory used by the object (for example UNIT objects allocate memory when the unit engine create them and release that memory only when the unit engine is destroyed). This method is called by the destructor to destroy the object as well, but the destructor may pass some additional parameters and do some extra work.

In fact it's related to the object model used in TA3D : destroy() only destroy the "object" not the associated "variable" in memory (I hope it's clear, I don't know if I would understand such a sentence :D )

PS: hm, I forgot : we tend to use malloc()/free() when we manipulate raw data and new/delete when we manipulate object, but you may find some code where it's not the case because I started TA3D using only malloc/free
=>;-D Penguin Powered

User avatar
AF
Administrateur - Site Admin
Posts: 139
Joined: Thu Dec 28, 2006 8:19 pm
Location: NW UK
Contact:

Post by AF » Sun Jun 08, 2008 3:22 pm

Ideally this sort of thing would be done in an object pooling system.

User avatar
zuzuf
Administrateur - Site Admin
Posts: 3281
Joined: Mon Oct 30, 2006 8:49 pm
Location: Toulouse, France
Contact:

Post by zuzuf » Sun Jun 08, 2008 3:45 pm

This is more or less what the unit, weapon, feature arrays are.
=>;-D Penguin Powered

Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests