Sign in to follow this  

How do you prefer to update your Instance Buffer?

Recommended Posts

mrheisenberg    362
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
VildNinja    789
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() {
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
kauna    2922
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this