Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Efficiency Question?  (Read 1060 times)
0 Members and 1 Guest are viewing this topic.
Offline Soljaragz

Junior Member





« Posted 2006-02-09 00:42:58 »

If I have a grid and each position on grid is an ArrayList

is it better to

1. Construct all the ArrayLists at initialization, and just leave them active, even if their is nothing in there.

2. don't make any ArrayList at initialization, but when an object moves to that spot, that instantiate an ArrayList and add it to the list, but if that object moves to a different grid, then delete that ArrayList, and make a new ArrayList, at that Enemies position

I've already done the first, and it works fine, but just wondering if is faster to do option 2.
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2006-02-09 09:43:12 »

If im understanding you, the only reason to do the latter is if you are trying to save memory.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Online princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #2 - Posted 2006-02-09 11:37:57 »

If the grid is large then yes, construct them lazily.

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #3 - Posted 2006-02-10 01:03:39 »

Oh was that  what he was asking?

I thought he was asking if he should dereference the lists when empty.


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Soljaragz

Junior Member





« Reply #4 - Posted 2006-02-10 05:34:56 »

but isn't time consuming to recreate objects?

I read somewhere that instead of deleting an element in the list ( that you would need later, but not at the moment), its best to not delete it, but put it in a arrayList and pull it out of the arrayList when you need it.

im pretty sure that is faster than the first two,..................right?

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2006-02-10 09:39:19 »

Most certainly even slower than reconstructing them.

Anyway... profile, then you don't have to ask, because then you *know* it.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline cylab

JGO Ninja


Medals: 49



« Reply #6 - Posted 2006-02-10 10:25:24 »

"Premature optimization is the root of all evil" [Tony Hoare]

Just optimize if you have a concrete performance-problem and do it after using a profiler ;-)

Mathias - I Know What [you] Did Last Summer!
Offline DzzD
« Reply #7 - Posted 2006-02-10 11:29:16 »

"Premature optimization is the root of all evil" [Tony Hoare]

Just optimize if you have a concrete performance-problem and do it after using a profiler ;-)

I totaly agree

Bruno

Offline Jeff

JGO Coder




Got any cats?


« Reply #8 - Posted 2006-02-11 01:48:37 »

Java allocation is lightening fast.  Collection of short lived objects is equally fast.

What you seem to be alluding to is "pooling".  On a modern (desktop) VM pooling almost never helps you, in fact it usually hurts you.  The exceptions are (a) If the object being allocated needs to allocate a system construct such as a Thread or a Socket (the system is slow to give these to you) OR you have so over complicated a constructor that YOU are making allocation slow.

It sound like you've been listening to either very old advice or advice from C/C++ programmers.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
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.

BurntPizza (19 views)
2014-09-21 02:42:18

BurntPizza (14 views)
2014-09-21 01:30:30

moogie (14 views)
2014-09-21 00:26:15

UprightPath (25 views)
2014-09-20 20:14:06

BurntPizza (27 views)
2014-09-19 03:14:18

Dwinin (40 views)
2014-09-12 09:08:26

Norakomi (73 views)
2014-09-10 13:57:51

TehJavaDev (96 views)
2014-09-10 06:39:09

Tekkerue (49 views)
2014-09-09 02:24:56

mitcheeb (70 views)
2014-09-08 06:06:29
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!