Jump to content

  • Log In with Google      Sign In   
  • Create Account


How do you prefer to update your Instance Buffer?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 mrheisenberg   Members   -  Reputation: 356

Like
0Likes
Like

Posted 10 September 2012 - 06:50 AM

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?

Sponsor:

#2 VildNinja   Members   -  Reputation: 420

Like
0Likes
Like

Posted 10 September 2012 - 09:38 AM

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
}


#3 kauna   Crossbones+   -  Reputation: 2285

Like
0Likes
Like

Posted 10 September 2012 - 10:30 AM

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, 10 September 2012 - 10:34 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS