Jump to content
  • Advertisement
Sign in to follow this  
noodleBowl

Vector Push Back?

This topic is 954 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a quick question about std::vector and its push_back function
 
If I have this data class:
class DataBlock
{
   int blockID;
   float data[25000];
};

What happens, memory wise and with the block variable, when I do
//In some function
if(needNewDataBlock == true)
{
   DataBlock block;
   dataBlockVector.push_back(block);
}

Edited by noodleBowl

Share this post


Link to post
Share on other sites
Advertisement

And don't forget when working in batches to reserve enough space for everything in advance.

 

Resizing a vector is potentially a slow operation, especially when objects are not trivially movable.  Even when they are easily moved, code that triggers multiple vector resizes can have a huge performance hit.

Share this post


Link to post
Share on other sites

And don't forget when working in batches to reserve enough space for everything in advance.
 
Resizing a vector is potentially a slow operation, especially when objects are not trivially movable.  Even when they are easily moved, code that triggers multiple vector resizes can have a huge performance hit.


See this the tiny dilemma that I have. I want to better my sprite batcher as now it currently just does a intermediate mode (no sorting, no support for changing shaders, etc). But I do not know which is worse:

Creating and allocating additional VBOs for the GPU when I do not have a "free" VBO

OR

Creating one large VBO and have something like the batch class above.
Then when I do not have a "free / used" batch I create a new one and add it onto some vector

 

Boiling down using up more GPU memory or system memory 
Keeping in mind I am targeting mobile devices, using OpenGL es 2.0 where I do not have direct mapping functions for pushing data directly into a VBO.

Edited by noodleBowl

Share this post


Link to post
Share on other sites

Your dilemma does not match your concerns. Not sorting or no support for multiple shaders is not an STL issue, it is an architectural issue. Your two options you present are purely situational and based more on the experience the game is attempting to provide. The rate of creation for new assets as well as the upkeep of current assets plays more into this question than GPU vs System memory usage.

 

The first question you would ask yourself is if you need to constantly be adding new assets to memory, and if you do are you also deleting old ones at the same rate?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!