Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  Print  
  Object creation vs. an if statment  (Read 2614 times)
0 Members and 2 Guests are viewing this topic.
Offline princec
« League of Dukes »

JGO Kernel
*****

Posts: 8089
Medals: 96


Eh? Who? What? ... Me?


« Reply #30 on: 2011-08-21 17:25:30 »

I'd also suggest that using a copying sweep would be the fastest method still. That is, as you iterate the arraylist, copy the elements into a new arraylist that are still "live", and then switch to that arraylist, like a double-buffer. This should make absolutely the best use of caches.

Cas Smiley

Offline JL235

JGO Ninja
***

Posts: 660
Medals: 21



« Reply #31 on: 2011-08-21 18:00:42 »

I'd also suggest that using a copying sweep would be the fastest method still. That is, as you iterate the arraylist, copy the elements into a new arraylist that are still "live", and then switch to that arraylist, like a double-buffer. This should make absolutely the best use of caches.

Cas Smiley
That's an awesome idea. Even with 100,000 elements, live at once, your only going to be using around 390kb of memory.

Online Eli Delventhal
« League of Dukes »

JGO Kernel
*****

Posts: 3575
Medals: 44


Game Engineer


« Reply #32 on: 2011-09-09 17:38:18 »

I've only ever used this method for particle effects where there are hundreds or thousands of them created and deleted each frame. It's cheaper to pull ones already allocated off a queue than it is to deallocate them and reallocate new ones every frame.

Actually Apple's UIListView does this as well. This is their UI element when you are scrolling through a very long list of elements (like the address book), it only ends up allocating a few and changes their contents as you scroll through them. This however is because you only have a few on screen at once (like 10 maybe) so it doesn't make sense to allocate 200 of them. But you don't face that issue at all, really, and enemies on screen are not nearly as predictable as a list view.

See my work:
OTC Software
<br />
Currently Working On:
Secret project...
Quote from: _Riven
I edit JGO in production, because I simply don't waste time writing bugs
Pages: 1 [2]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.062 seconds with 19 queries.