Page 1 of 1

destroy() / free / malloc

Posted: Sat Jun 07, 2008 4:19 pm
by milipili
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.

Posted: Sat Jun 07, 2008 5:02 pm
by Balthazar
Well, when you see this string you should count from 1 to 100 :)

Posted: Sat Jun 07, 2008 5:05 pm
by zuzuf
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

Posted: Sun Jun 08, 2008 3:22 pm
by AF
Ideally this sort of thing would be done in an object pooling system.

Posted: Sun Jun 08, 2008 3:45 pm
by zuzuf
This is more or less what the unit, weapon, feature arrays are.