Results 1 to 6 of 6

Thread: Array of objects in java

  1. #1
    Join Date
    Dec 2009
    Posts
    204

    Array of objects in java

    Hello,
    For a game, I need a map shown in (grid size nxm). Each box can have different characteristics (type of field, players on this box). If I create an object Case by case I fear that it takes too many resources. I want to know what size take a minimum object in memory. That is I am trying to create array of objects And if there would be a better solution than the table of Case?

  2. #2
    Join Date
    Nov 2009
    Posts
    583

    Re: Array of objects in java

    Hello,
    The size of an object is the sum of the size of its attributes. Whether the pose problem is easy or not, you have to follow this rule.
    Code:
    (sum of the size of attribute * case maximum)
    The above must not exceed say 30% of your RAM. I hope this is correct, but I think you do not have to take a risk by not following this. I hope you will remember this.

  3. #3
    Join Date
    Nov 2009
    Posts
    518

    Re: Array of objects in java

    Hello,
    If you study your case well, there is no reason. You can create 100,000 spaces, you make a small database for backup, etc.. And do not forget this little maxim which I like very much.
    Some tips for you
    Code:
       1. Do not optimize.
       2. (Experts only) do not optimize yet.
    I think you should follow this in your code.

  4. #4
    Join Date
    Nov 2009
    Posts
    446

    Re: Array of objects in java

    Hello,
    To optimize has a very wide meaning.

    - Optimize the meaning "using an algorithm more efficient" (change of treatment, recasting of all classes) is a good thing in java.

    - Optimize the meaning 'think assembler "(minimum booking memory, thinking the power of 2 in the calculations etc..)

    To conclude, should see what kind of optimization is spoken of: seek to win a CPU cycle (I exaggerate), or try to win 90% of time with a better algorithm.

  5. #5
    Join Date
    Nov 2009
    Posts
    347

    Re: Array of objects in java

    Hello,
    Although the study of algo means nothing other than winning processor cycles (or worse, to be generic). I like this maxim, because - I believe - it raises the question: But if I can not optimize, then what can I do to improve my code? ... Should be computer expert, this is not optimal, so what? My answer to me is to do a code of algorithms appropriate service to be rendered. The optimization is simply to be in tune with what to do, just like the real-time systems.

  6. #6
    Join Date
    Nov 2009
    Posts
    359

    Re: Array of objects in java

    Hello,
    You should know that in Java, an int is coded example of 4 bytes. If your subject has Case 50 attributes of type int, it will only take 200 bytes in memory, which is very low. You can create objects Box 10 000, it will be a total of 2 million bytes, that is to say approximately 2 MB, which is reasonable (The current machines are the order of GB). As the table of Case, it takes almost no resources in memory, is just a mailing list references (addresses) to objects. No problem, you should start taking care of memory allocation when you have a StackOverflow.

Similar Threads

  1. Advanced Cache Objects in Java
    By StudyBoy in forum Tips & Tweaks
    Replies: 3
    Last Post: 31-07-2010, 03:41 PM
  2. Return value of generic objects in java
    By Amy Adams in forum Software Development
    Replies: 4
    Last Post: 30-03-2010, 11:42 AM
  3. What are an Immutable Objects in Java?
    By Silent~Kid in forum Software Development
    Replies: 4
    Last Post: 19-02-2010, 06:35 AM
  4. Access to Objects In A JavaBean From Another Java Bean
    By ramsun in forum Software Development
    Replies: 5
    Last Post: 30-01-2010, 01:18 PM
  5. Array of Objects to call constructor
    By KALLIYAN in forum Software Development
    Replies: 3
    Last Post: 04-11-2009, 09:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,958,519.27364 seconds with 17 queries