C++ Spawning new objects in a game engine
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 ?
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.
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.
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.
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
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
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! =)
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! =)
Thanks for the all the advice...
I''m gonna go the custom memory management route.
I''ll keep you posted
I''m gonna go the custom memory management route.
I''ll keep you posted
I just wrote something similar for the game my company is working on, so let me know if you have any questions.
-- Steve --
-- Steve --
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement