Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411595 Posts in 69387 Topics- by 58445 Members - Latest Member: gravitygat

May 08, 2024, 07:01:47 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Garbage collector idea for my game system - feedback?
Pages: [1]
Print
Author Topic: Garbage collector idea for my game system - feedback?  (Read 2564 times)
rogerlevy
Guest
« on: March 24, 2009, 06:38:25 PM »

I've been thinking that an efficient GC might be a very nice thing to have as part of the scripting language of my game tool that I'm working on.

I was wondering if people think that this scheme is a good idea.  It is a variation on reference counting.  (Sorry, most folks may find this boring and TOO nerdy, this is probably only interesting to true egg heads... does that make me one?  Shocked)

Ok, so to use the scheme in my language, I cannot overload any operators so using the GC's features is actually explicit but pretty simple.  It does at least still remove the need to manage memory yourself.  Here is the set of keywords that must be used and what they would do:

ref! - store a reference, inc ref counter of the referred obj
ref@ - fetch reference, set "do not clear" flag of that obj
deref - clear reference, dec ref counter of that obj, delete it if the counter reaches 0.
protect - add obj to list of objects not to delete (or mark it with a flag)
release - release an object explicitly so that it can be deleted by the GC. cancels PROTECT.

The last two are needed because in my setup I try to solve the "circular reference" issue by only deleting objects references that are not USED by any code during a GC cycle.  however this may not be wanted sometimes (in the case of theoretical "idle" objects... i don't know, such as objects in a different room than the one the player is in) so i have a simple mechanism for preventing that.  PROTECT and RELEASE could be recursive so if called on a collection all children would also be affected.

thoughts? ideas?

and most importantly, is it practical?
Logged
rogerlevy
Guest
« Reply #1 on: March 25, 2009, 04:07:25 AM »

eh, seems to me now that this post isn't that useful.  also it's going against me that i can't really post example code, so people can't know what context these keywords would be used in.  mods, you can delete this thread.
Logged
Eclipse
Level 10
*****


0xDEADC0DE


View Profile WWW
« Reply #2 on: March 25, 2009, 04:25:10 AM »

personally i'm always against garbage collectors that runs while the game runs or worse stuff that takes a thread on their own, my engine has just a list of pointers for all the allocated stuff and it releases everything on quit or with a specific function call, to release and manage stuff during the game, like loading the current level and deleting the previous one things, you have to do it yourself in the game code destroying the "level" class for example.

so basically i have no flags at all and there's really no need for this stuff, also because spending in-game time doing memory shit is the best way to kill your framerate
Logged

<Powergloved_Andy> I once fapped to Dora the Explorer
rogerlevy
Guest
« Reply #3 on: March 25, 2009, 05:32:29 AM »

Thanks Eclipse for the input, I will keep that in mind.

I don't think I'll bother with trying to add it.
Logged
Core Xii
Level 10
*****


the resident dissident


View Profile WWW
« Reply #4 on: March 25, 2009, 07:10:26 AM »

I never understood garbage collectors in the first place. What's wrong with manually releasing stuff when it's not needed? Especially with games where there are very specific events that release resources (changing levels, etc.).
Logged
Hajo
Level 5
*****

Dream Mechanic


View Profile
« Reply #5 on: March 25, 2009, 07:16:51 AM »

What's wrong with manually releasing stuff when it's not needed?

Nothing wrong with that. It's just that some people like it better if the runtime handles that for them, others like it better to handle it by themselves.
Logged

Per aspera ad astra
Mikademus
Level 10
*****


The Magical Owl


View Profile
« Reply #6 on: March 25, 2009, 07:36:03 AM »

If your script language supports scoping and stack allocation then you'd be better off with RAII. If you want objects to survive across scopes then either support globals (which will be deallocated at script termination) or "manual" (that's a good keyword, eh?) objects, several flavours exist, the three principal being global (already mentioned), statically and dynamically allocated objects.
Logged

\\\"There\\\'s a tendency among the press to attribute the creation of a game to a single person,\\\" says Warren Spector, creator of Thief and Deus Ex. --IGN<br />My compilation of game engines for indies
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic