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]
  Print  
  Collections API in ArcadeGame Programming?  (Read 1382 times)
0 Members and 2 Guests are viewing this topic.
Offline 20thCenturyBoy

Full Member
**

Posts: 118


Ooh my head hurts...


« on: 2004-05-20 20:20:03 »

Does the Collections API incur too much of a performance hit in arcade-style Java games? I really like the API but I have a sneaky suspicion that it is probably overkill for games where an array can do the job. Am I right? Or am I prematurely optimizing?

20thCB
Inquisitor
Guest
« Reply #1 on: 2004-05-20 20:49:30 »

At least ArrayList, LinkedList and HashMap are fine. I haven't actually used others nearly at all. I wouldn't suggest to use Iterators though.
Offline D.t.O

Full Member
**

Posts: 130


Psych'd about Java Games


« Reply #2 on: 2004-05-20 22:56:11 »

LinkedList is definitely not OK if you want to frequently access stuff in the middle, which is an O(n) operation.

Don't know if that was any use at all because most people already know it Embarrassed

Enjoy.
Regards,
     - D.t.O
Games published by our own members! Go get 'em!
Offline Herkules

JGO Kernel
*****

Posts: 1522
Medals: 1


Friendly fire isn't friendly!


« Reply #3 on: 2004-05-21 01:39:49 »

Cannot imagine anything more usefull and fast as HashMap/HashSet. Don't know how I ever could live without....

Ok, in ancient C times I had an array of things and iterated over it when looking up things Sad

I don't think collections are a performance problem. Used right, they can be a big performance gain!!!

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline abies

Sr. Member
**

Posts: 456



« Reply #4 on: 2004-05-21 02:32:02 »

Code using collections available in JDK (correct types of course). Inside class use specific types, but for inter-method communication use interfaces, so you can replace implementations easily.

When you will finishin your application, profile. You will probably find many other places to optimize. If after that, collections will prove to be a problem (most probably because need to creating wrappers for primitives for maps), switch to trove[1] in critical places and profile again.

Be sure to do that as late as possible - trove has very different performance characteristic than jdk collections. For example, trove hashmap memory usage is dependent only on size of it, while in JDK it is a strong function of number of values contained inside. Trove will always use only a few objects, where in JDK you will get at least one extra object per entry. Trove use different collision resolution, so depending on size of map and distribution of hashcodes, it can be few times faster or few times slower[2]
Generally, I have observed trove to be a _bit_ faster and a _bit_ less memory hungry for most cases, and a considerably cheaper garbage-wise for primitive->primitive mappings. I have used it mostly to avoid casting Wink

[1] http://trove4j.sourceforge.net/
[2] Don't believe benchmarks on trove page - they are designed to make trove win by wide marigin

Artur Biesiadowski
Inquisitor
Guest
« Reply #5 on: 2004-05-21 05:33:59 »

Quote
LinkedList is definitely not OK if you want to frequently access stuff in the middle, which is an O(n) operation.

Don't know if that was any use at all because most people already know it Embarrassed


I mean't that the Java implementation of LinkedList should be quite fast (though I've mostly used ArrayList). And you should use arraylist if you want random access.
Offline D.t.O

Full Member
**

Posts: 130


Psych'd about Java Games


« Reply #6 on: 2004-05-21 23:01:52 »

No offense Inquisitor Wink

Enjoy.
Regards,
     - D.t.O
Inquisitor
Guest
« Reply #7 on: 2004-05-22 07:48:36 »

No offense taken Smiley
Pages: [1]
  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.105 seconds with 25 queries.