How do you prefer to update your Instance Buffer?

Started by
1 comment, last by kauna 11 years, 7 months ago
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?
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
}
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!

This topic is closed to new replies.

Advertisement