Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » Renegade C++ Cleanup
Renegade C++ Cleanup [message #437105] Mon, 27 September 2010 16:31 Go to next message
halo2pac is currently offline  halo2pac
Messages: 659
Registered: December 2006
Location: Near Cleveland, Ohio
Karma: 0
Colonel
Hey guys.
I'm working on a lot of C++ that has to do with renegade in general (servers, scripts, ect).

When you write code in let say a script what do you have to delete to make sure you don't have any memory leaks?

So far I know of when you create a string like:
const char *Nick

you have to delete it.


what other things are there to delete, and how do I delete them?

*off the top of my head Vector3 is one of the ones where I am wondering if I have to delete it after creating one.

Thanks!


http://img339.imageshack.us/img339/1991/nefobbygenyunoreleasere.jpg
Rene-Buddy | Renegade X
Join the fight against Obsessive-Compulsive Posting Disorder. Cancel is ur friend.
*Renegade X Dev Team Member*
Re: Renegade C++ Cleanup [message #437109 is a reply to message #437105] Mon, 27 September 2010 19:19 Go to previous messageGo to next message
jonwil is currently offline  jonwil
Messages: 3557
Registered: February 2003
Karma: 0
General (3 Stars)

Basically anywhere you see something like new char[100], thats allocating memory that you need to clean up.
If you do something like Vector3 v;
v.X = 1;
v.Y = 1;
v.Z = 1;
then, no, you dont have to clean up that Vector3.


Jonathan Wilson aka Jonwil
Creator and Lead Coder of the Custom scripts.dll
Renegade Engine Guru
Creator and Lead Coder of TT.DLL
Official member of Tiberian Technologies
Re: Renegade C++ Cleanup [message #437143 is a reply to message #437105] Tue, 28 September 2010 06:39 Go to previous messageGo to next message
halo2pac is currently offline  halo2pac
Messages: 659
Registered: December 2006
Location: Near Cleveland, Ohio
Karma: 0
Colonel
Then I have a 1000 memory leaked lol. How do u clean up a char test[]?

http://img339.imageshack.us/img339/1991/nefobbygenyunoreleasere.jpg
Rene-Buddy | Renegade X
Join the fight against Obsessive-Compulsive Posting Disorder. Cancel is ur friend.
*Renegade X Dev Team Member*
Re: Renegade C++ Cleanup [message #437146 is a reply to message #437105] Tue, 28 September 2010 07:18 Go to previous messageGo to next message
Omar007 is currently offline  Omar007
Messages: 1711
Registered: December 2007
Location: Amsterdam
Karma: 0
General (1 Star)
afaik just do
delete test;


But to be honest I never deleted that stuff in my scripts.. (yet Razz)


http://tiberiumredux.omarpakker.nl/Old Unused Parts/Plaatjes/PromoteBanner_Hades_small.jpg

[Updated on: Tue, 28 September 2010 07:19]

Report message to a moderator

Re: Renegade C++ Cleanup [message #437155 is a reply to message #437105] Tue, 28 September 2010 09:19 Go to previous messageGo to next message
jonwil is currently offline  jonwil
Messages: 3557
Registered: February 2003
Karma: 0
General (3 Stars)

If you have something like this
char test[100];
then you dont need to do anything to delete it, it gets deleted automatically.


Jonathan Wilson aka Jonwil
Creator and Lead Coder of the Custom scripts.dll
Renegade Engine Guru
Creator and Lead Coder of TT.DLL
Official member of Tiberian Technologies
Re: Renegade C++ Cleanup [message #437157 is a reply to message #437105] Tue, 28 September 2010 10:29 Go to previous messageGo to next message
saberhawk
Messages: 1068
Registered: January 2006
Location: ::1
Karma: 0
General (1 Star)
The rules basically are:


  • If you called new on it, use delete on it when you no longer need it.
  • If you called new[] on it (ie char* test = new char[128]Wink, use delete[] on it.


Debug mode builds enable the memory manager code in 3.4.4. iirc not all of the "leaks" listed can be fixed, but they do show where allocations occurred. Certain leaks were fixed in code released by me not included with 3.4.4 (notably a SurfaceClass leak that sometimes causes lag on exit) and the changes themselves were likely also documented in a post of mine.
Re: Renegade C++ Cleanup [message #437159 is a reply to message #437105] Tue, 28 September 2010 10:49 Go to previous messageGo to next message
cAmpa is currently offline  cAmpa
Messages: 597
Registered: March 2006
Karma: 0
Colonel
I think i don't know all your fixes, could you show me all?

Bückstabü!
Re: Renegade C++ Cleanup [message #437160 is a reply to message #437159] Tue, 28 September 2010 10:59 Go to previous message
saberhawk
Messages: 1068
Registered: January 2006
Location: ::1
Karma: 0
General (1 Star)
cAmpa wrote on Tue, 28 September 2010 13:49

I think i don't know all your fixes, could you show me all?


Gladly; I just need you to show me all the fixes I've made. Razz I don't actually remember all the changes I've made, searching for posts made by me is going to give you better results. One thing I'm pretty sure of is that newer posts I've made including code still contain the fixes of earlier posts.
Previous Topic: Just a Musical Thought
Next Topic: C&C_M01 *wip* video
Goto Forum:
  


Current Time: Mon Nov 18 11:12:06 MST 2024

Total time taken to generate the page: 0.00788 seconds