Jump to content
  • Advertisement
Sign in to follow this  
mrheisenberg

How do you prefer to update your Instance Buffer?

This topic is 2140 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

Do you replace the array in the instance buffer every frame or is there something else?I heard that using the 'new' keyword too much causes memory fragmentation or something and if I destroy and create instance arrays with 1000 elements in them every frame,that would be bad?

Share this post


Link to post
Share on other sites
Advertisement
Yes that would be bad. Allocating memmory on the heap is a cumbersome task for the cpu.

I am not quite sure what you are talking about, but the most common buffering, is to use two arrays and have a single bool telling which array is being displayed, so you can plot data into the other before flipping the bool and displaying the first.


Element[] a = new Element[1000]
Element[] b = new Element[1000]
bool showA = true;
GameLoop () {
while (true) {
showA = !showA;
Update();
Draw();
}
}
Update() {
Element[] buffer = (showA ? b : a);
// do stuff to buffer
}
Draw() {
Element[] buffer = (showA ? a : b);
// display stuff from buffer
}

Share this post


Link to post
Share on other sites
Isn't updating instance buffer more like copying data than allocating new memory?

Otherwise, I copy every frame instance data of every object to a buffer object and it doesn't involve using new keyword / creating new objects / deleting objects.

Of course if there is a way to avoid copying, that's even better. From my experience a couple of megs of instance data per frame doesn't really hurt the performance.

Cheers! Edited by kauna

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!