Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Safe coding practices

Author
Message
Aldur
17
Years of Service
User Offline
Joined: 8th Oct 2007
Location: Melbourne, Australia
Posted: 26th Feb 2010 01:39
Another question which I think deserves a bit of detail is this:

What has to be done to ensure the system returns to the same state after an application made in GDK has run. Things to prevent memory leaks and things like that.

I know the usual delete objects, images, sounds, sprites, memblocks and the like, but what are other methods of 'cleaning up' on exit?

Should classes and structs be deleted?

Thanks all.

Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 26th Feb 2010 02:32 Edited at: 26th Feb 2010 02:40
Quote: "Should classes and structs be deleted?"


Remember to delete/free the memory that you use new/malloc for. That means deleting every char* that comes from DarkGDK, since it allocates new memory every call. Everything else just gets destructed when it falls out of scope.

Success = Determination * Mood;
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 26th Feb 2010 03:14
I had the impression that with the latest couple versions of GDK it did not require you to delete your objects images sprites etc, now char*'s and such I know you must manually remove. But am I wrong about the objects and images and such??
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 26th Feb 2010 13:15
I think images, objects and the like get deleted when the program exits, don't they?
Otherwise your memory would be pretty full after a couple runs I guess. Please correct me if I'm wrong...

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 26th Feb 2010 14:06
Windows has freed all memory allocated by your application one it's terminated for the past decade so you don't have to worry about it. But it's good practice to deallocate everything before termination, otherwise you may run into issues if destructors are called in the wrong order, or some routine needs to be run before the destructor or something.

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 26th Feb 2010 14:38 Edited at: 26th Feb 2010 14:39
As said above, all allocated memory is freed on application exit (a feature provided by Windows), although you will need to manage deallocation of strings yourself (as DGDK allocates them all over the place) otherwise the longer your application runs, the more memory it will be using.

Login to post a reply

Server time is: 2024-11-19 15:41:48
Your offset time is: 2024-11-19 15:41:48