Jump to content

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

How do you prefer to update your Instance Buffer?

4: Adsense

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   

360
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?

#2 VildNinja   Members   

788
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   Members   

2922
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.