Archived

This topic is now archived and is closed to further replies.

N0T0R10US

C++ Spawning new objects in a game engine

Recommended Posts

I've developed a simple game engine, deriving all game objects from a simple base class and storing pointers to them in a linked list which I process in the main game loop. What's the best approach to spawning short lived objects. Will I take a performance hit if I add them to the linked list only to remove them a couple of cycles later ? Or do I reserve space for the maximum number of objects in one go and live with the overhead ? Sorry, this a pretty generic q. Is there a rule of thumb, irrespective of the game genre ?

Share this post


Link to post
Share on other sites
During runtime you''d want to be using new as little as possible, so reserving space for the maximum amount is probably the best way to go.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It''s always learning a few tricks from the masters (id etc.) - have a look at the source code for Doom, Quake and the like. They tend to allocate a big chunk of memory when the game initialises and use their own memory management to handle allocations dynamically.

I seem to remember seeing something in the source code for Quake which does something to make sure that Windows doesn''t page the memory out to disk (obviously making things very slow!) - can''t remember exactly what it was but like I said, have a look at the source code and pick up some tips.

Share this post


Link to post
Share on other sites
I''m a little too lazy to trawl throught the source code for Quake, but I like the idea of a custom memory management module.

I''ve read recently that if paging to disk wasn''t enough to worry about, that there are performance wins to be made by programming around the memory cache.

Just want to make sure I get off on the right foot. They''ll be plenty of time to tune near the end of my project.

Thanks for the advice so far

Share this post


Link to post
Share on other sites
Depends on how many objects to create. If you use a recycling array that reservs memory at start, you won''t have any trouble with that later, but I usually use some sort of stl container.

list, queue, map or vector depending on what kind of things to be managed. This is not the most optimized way, but it''s pretty fast and very easy! =)

Share this post


Link to post
Share on other sites
I just wrote something similar for the game my company is working on, so let me know if you have any questions.

-- Steve --

Share this post


Link to post
Share on other sites