Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6991499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:30:39+00:00 2026-05-27T19:30:39+00:00

So I am part way through writing my first game on Android and after

  • 0

So I am part way through writing my first game on Android and after watching a lengthy presentation on optimising for games, I have been checking my allocations. I have managed to get rid of all in-game allocations apart from ones made my ArrayList when it creates an implicit iterator for the for(Object o : m_arrayList) convention.

There are a fair few of these iterations/allocations since all of my game objects, ai entities etc. are stored in these for their ease of use.

So what are my options?

  • I could, theoretically specify sensible upperbounds and use arrays, but I like the features of ArrayList such as exists and remove that keep code clean and simple.

  • Override ArrayList and provide my own implementation of iterator() that returns a class member rather than allocating a new iterator type each time it is used.

I would prefer to go for option 2 for ease of use, but I had a little go at this and ran into problems. Does anyone have an example of what I described in option 2 above? I was having problems inheriting from a generic class, type clashes apparently.

The second question to this then is are there any other options for avoiding these allocations?

And I guess as a bonus question, Does anyone know if ArrayList preallocates a number of memory slots for a certain amount (specified either in the ctor or as some shiftable value) and would never need to do any other allocations so long as you stay within those bounds? Even after a clear()?

Thanks in advance, sorry there is so much there but I think this information could be useful to a lot of people.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:30:40+00:00Added an answer on May 27, 2026 at 7:30 pm

    Use positional iteration.

    for ( int i = 0, n = arrayList.size( ); i < n; ++i )
    {
       Object val = arrayList.get( i );
    }
    

    That’s how it was done before Java 5.

    For preallocation.

    ArrayList arrayList = new ArrayList( numSlots );
    

    or at runtime

    arrayList.ensureCapacity( numSlots );
    

    And for a bonus -> http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are new to Scrum and part way through the first sprint we have
I'm currently writing an OpenGL renderer and am part-way through writing some classes for
I've encountered a problem where part way through building a solution, VS 2010 becomes
As part of a project I have assigned myself as a way of improving
I develop the first part of an Android application that allows to broadcast video
I have been writing something to read a request stream (containing gzipped data) from
I'm writing my first CakePHP application and am just writing the second part of
The good folks at stackoverflow helped me part of the way with this, now
Any way to get a dash as part of a property name in C#?
Is there any way to adjust the boundaries of the visible part of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.