Hi !
Featured games (87)
games approved by the League of Dukes
Games in Showcase (672)
Games in Android Showcase (194)
games submitted by our members
Games in WIP (727)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Performance Tuning / Re: clearing or make new array? on: 2014-06-02 03:06:24
Ugh, this sounds exactly like an Object Pool to me. But, then you wouldn't need to delete the Objects, instead, you would just set them to a value that you wouldn't use so they can be used again. Below is an implementation for objects (not written by me but borrowed...)

     * Acquires an object from the pool, if a recycled one is available, then
     * the pool will return the recycled one rather than creating a new one.
     * @return object instance

    public final T acquireObject()
        if( collectedTrash.size() > 0 )
            return collectedTrash.remove(0);
            return createInstance();

You realise when you call collectedTrash.remove(0) you're causing the entire backing array of ArrayList to be copied 1 place to the left?  If it's large you're probably costing yourself a lot more than you gain from eliminating GC.  Better off using a LinkedList or collectedTrash.remove(collectedTrash.size() - 1).

edit:  Don't use a LinkedList because that will create another wrapper object which will get GC'd in place of the pooled object.
Pages: [1]
IanParcs (56 views)
2016-04-18 14:18:53

KaiHH (52 views)
2016-04-18 08:35:41

KaiHH (82 views)
2016-04-15 12:43:58

theagentd (84 views)
2016-04-14 02:16:17

theagentd (100 views)
2016-04-14 02:15:43

IanParcs (123 views)
2016-04-12 03:51:16

IanParcs (54 views)
2016-04-12 03:50:03

IanParcs (52 views)
2016-04-12 03:49:54

IanParcs (48 views)
2016-04-12 03:49:52

IanParcs (56 views)
2016-04-12 03:49:52
Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50

Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!