Skip to main content
gamedev.net
🔒 Locked

efficient memory allocation

Started by wannabe H4x0r Mar 8, 2003 at 5:12 PM 1 replies 200+ views
Original Post
wannabe H4x0r
wannabe H4x0r
i''m trying to decide what is the most efficient way to allocate memory, specifically in my graphics engine. i need to be able to dynamically load at runtime 3d models and so i need some way to allocate space for vertices. i have two way of doing this, one is to allocate an array of pointers and create a new[] array for every object created, or i could have a huge staticly allocated array of vertex structures and assign parts of the vertex buffer to various objects as needed. my question is what''s the difference performance wise between using pointer assignment and traversal and a continuous static buffer? this question could apply to actually any other part of the program so it''s going under general programming.
Monder
Monder
I believe the continuos static buffer may be faster because there''s no memory allocation however it''ll constantly take up a fixed amount of memory(some of which you may not be using) and if you need more then you''re screwed.

I''d go with the first option if it''s for loading object then it''s not going to be called that frequently so any memory allocation overhead you may have(and I don''t think it''s really that much) won''t matter and you can have as many objects as you want (within the confines of the computers memory size of course)
Zipster
Zipster
You could do something between static and dynamic memory allocation. Allocate a buffer of a fixed size when you first start. Then, if you need more space, allocate another large block. This way, you can keep the buffer growing if you need to, but you won''t need frequent memory allocations.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.