Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (499)
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 1802 times)
0 Members and 1 Guest are viewing this topic.
Offline 20thCenturyBoy

Senior Member


Medals: 3


So much to learn, so little time.


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

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




Psych'd about Java Games


« Reply #2 - Posted 2004-05-21 04: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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Herkules

Senior Member




Friendly fire isn't friendly!


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





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

Junior Member




Psych'd about Java Games


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

No offense Inquisitor Wink

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

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

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (46 views)
2014-04-15 18:08:23

BurntPizza (42 views)
2014-04-15 03:46:01

UprightPath (58 views)
2014-04-14 17:39:50

UprightPath (40 views)
2014-04-14 17:35:47

Porlus (56 views)
2014-04-14 15:48:38

tom_mai78101 (79 views)
2014-04-10 04:04:31

BurntPizza (138 views)
2014-04-08 23:06:04

tom_mai78101 (238 views)
2014-04-05 13:34:39

trollwarrior1 (199 views)
2014-04-04 12:06:45

CJLetsGame (207 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org 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‑gaming.org
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!