Archived

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

SamuraiProgrammer

Does memory allocation incur alot of overhead?

Recommended Posts

Im sorry if this is in the wrong forum. Its kind of an openGL problem and a general programming one. Ive just started using alpha blending in openGL to get transparent effects. And Ive learnt that to display them properly with depth testing enabled I have draw all the transparent polys after the solid polys and in reverse order from the farthest to the nearest. As I will be using a particle system effect the number of transparent polys in the scene will be increasing and decreasing. So I thought of using a linked list to store all the alpha polys in, sorting through the list to put them in the correct drawing order. Then passing the list to a rendering function to draw. I was wondering if someone could tell me if using dynamic memory allocation i.e. malloc command, would take alot of time, and eat up frame rates. Or is it worth using dynamic memory allocation to save on the memory..(which isnt too important right now .. and people seem to have alot of memory these days) If malloc does incur too much of a penality.. I can always use an array of structs with the number of elements in excess of the amount I know i will need Thanks in advance for any help.

Share this post


Link to post
Share on other sites
malloc is not as slow as free, but it''s probably better to allocate what you need ahead of time and realloc if you need more. After you get everything working, adjust the allocation so that it''s less likely that you will have to realloc.

Share this post


Link to post
Share on other sites