Posts Tagged ‘C’

h1

reference counter based memory management + bitching about life

June 8, 2009

The bitching about life part comes first.  I believe the DCFC song “No Sunlight” sums up my rant in that regard nicely, so I won’t waste the space here.  Okay I’m done with that.

Now, on to the not depressing stuff.  I was thinking of ways I could potentially speed up memory management with threads.  I was basically thinking along these lines:  I should queue my object deletions so that I can delete them on the side while the next iteration is in progress.  So I came up with an interesting system.  I haven’t implemented the threading yet, but I have seperated object deletion from the main loop entirely and it’s just tacked on the end for now.

Basically I implemented a reference counter object management system.  Each ManagedObject has a grab() and drop() method, used to count references.  When the number of references reaches zero, the drop() method calls the queue_deletion() method in the ObjectManager singleton.  The ObjectManager also keeps track of ManagedObject’s that are still kicking, so that they can be cleaned up at the very end if they weren’t properly dropped.  This should keep memory leaks from being as bad, though that doesn’t mean I won’t bust my ass trying to find all of them.  So the current code for updating is as follows:

void Engine::RunMainLoop(double timestep)
{
while (running)
{
if (!Update(timestep)) running = false;
if (!Render()) running = false;
ObjectManager::Singleton().CleanUp();
}
}

The ObjectManager deletes all things queued for deletion in CleanUp(). What I could do is simply start a cleanup thread that cleans up every second or so. For the threaded version it will lock the mutex for the queue to copy it over to a private queue and clear the public one so that it can be used again while the cleanup iterator goes through and deletes everything added previously. If you want the full classes, I shall have t3h c0dez in an article on custom memory management for C++ classes shortly.

EDIT: Okay, article’s up. It’s called “C++ custom memory management primer”. Link under My Articles in the sidebar.

h1

t3h engine project + games == omg no work

December 1, 2008

Seriously.  I have Portal on here now, and beat it, but it ate up like two days of work time.  And also Zombie Panic, that’s still killing time.  At least I don’t have TF2, or I’d never get anything done, ever.  EVAR  :B

aaaannnnyyywaaaayyyy………..

I think the engine project could use some revival.  I like the code I have so far, and I still want to work on Floculate.  BY THE WAY OMFG I SPELLED IT WRONG BITCH.  It’s actually Flocculate.  And the word should be Flocculation.  Oh well.

But I want to revamp it to a certain extent.  Redo the system stuff for Win32/Linux, and less tacked on and more tied in properly support for stuff I plan to use like FBOs.  I also am strongly considering C++ for the Renderer.  The reason I am, is that it is far more flexible from a programming standpoint.

And all you people who are like “ur a devout C programmer omg thats liek total sellouting ur believes wtf!!1!”  Then I’m all “shut up foo!”  Seriously though.  C++ is appropriate in application settings.  Physics is C material.  All the necessary operations can be done in C, and it’s speed critical because it’s done on the CPU (by me anyway.)  It’s a necessity that it be as optimized as possible.  The same way OpenGL and DirectX were both written in C, because they are also optimized system level work.  But the USE of an optimized system level library like DirectX, OpenGL, or Rat Physics, is application work, and if it benefits greatly in terms of development from using C++, I’m down with that.

If you still don’t get the distinction, then either you weren’t a programmer and therefore that section is pointless to you, (you are pardoned non-programmers,) or you’re a dogmatic closed-minded jerk that doesn’t understand “circumstances” and their existence due to “dynamic reality.”  Seriously, take your fundamentalism somewhere else.  Once again, this only applies to the people screaming ‘hypocrite’ at me.  I know they exist, I know a few in person.

BTW, DirectX may be written in C++, we’ll never know.  It SHOULD be written in C.  I know it has a C interface anyway.

EDIT:  SUPER UPDATE TIME!  I now have a name for my engine, and it is made of recursive acronym GLORY!  RAVEN.  It means RAVEN Audio Video ENgine.  BRILLIANCE P0R W00T4G3!  Of course this is a part of Rampancy Engine.  The other part nearing completion is Rat Physics.  I also want to add more components, but that is for another time.