Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (593)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (647)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Collections API in ArcadeGame Programming?  (Read 2259 times)
0 Members and 1 Guest are viewing this topic.
Offline 20thCenturyBoy

Senior Devvie

Medals: 3

So much to learn, so little time.

« Posted 2004-05-21 00: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?


"I have never done unit testing and I don’t find it a very useful concept" - Jonathan Blow
« Reply #1 - Posted 2004-05-21 00: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

Junior Devvie

Psych'd about Java Games

« Reply #2 - Posted 2004-05-21 02: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

     - D.t.O
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Herkules

Senior Devvie

Friendly fire isn't friendly!

« Reply #3 - Posted 2004-05-21 05: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

Senior Devvie

« Reply #4 - Posted 2004-05-21 06: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

[2] Don't believe benchmarks on trove page - they are designed to make trove win by wide marigin

Artur Biesiadowski
« Reply #5 - Posted 2004-05-21 09:33:59 »

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

Junior Devvie

Psych'd about Java Games

« Reply #6 - Posted 2004-05-22 03:01:52 »

No offense Inquisitor Wink

     - D.t.O
« Reply #7 - Posted 2004-05-22 11:48:36 »

No offense taken Smiley
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

deepthought (38 views)
2015-06-30 15:39:44

deepthought (42 views)
2015-06-30 15:39:09

deepthought (53 views)
2015-06-30 15:36:52

Za\'Anzabar (24 views)
2015-06-29 05:44:54

TritonDreyja (40 views)
2015-06-24 17:10:40

CopyableCougar4 (36 views)
2015-06-23 00:34:45

BurntPizza (42 views)
2015-06-21 20:36:46

cookiecompiler (85 views)
2015-06-11 15:42:53

cookiecompiler (48 views)
2015-06-11 15:41:14

NegativeZero (76 views)
2015-06-11 09:49:18
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14 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!