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

  • Home
  • SEARCH
  • 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 4234726
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:23:47+00:00 2026-05-21T02:23:47+00:00

I am working on porting a Roguelike dungeon adventure game to the Android. http://tyrant.sourceforge.net

  • 0

I am working on porting a Roguelike dungeon adventure game to the Android.
http://tyrant.sourceforge.net

When I start my program, I initialize the world and all it’s objects first. I have a class that contains 3 million(!) HashMap entries. When I try to initialize that class, it takes 5+ minutes to run on my Android, which is a very unacceptable length of time. Once the class is is initialized, the game runs great and is quite fun.

So I thought I could serialize this object and reload it at runtime. I serialize it, and pack it in the .APK file, it’s over 5MB in size. Android just chokes and gives me an OutOfMemory error.

I can deserialize part of the class(800KB), and then dynamically create the rest of entries. That still takes quite a few minutes to finish too, it still has to create 3 million entries from the serialized data. But I do know that my serialization code works fine.

How can I store this very large class file on the Android and load it later? What are some options I can explore? Making my user wait 5 minutes for the app to start is not very good at all.

Here is the troubling class in the original source code:
http://tyrant.cvs.sourceforge.net/viewvc/tyrant/tyrant/mikera/engine/Lib.java?view=markup

and the troubling field is:

private transient Map types;

(I’m aware it’s transient)

it ends up storing over 3 million entries!

  • 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-21T02:23:48+00:00Added an answer on May 21, 2026 at 2:23 am

    Well part of the problem is what is in the types map.

    From what I can make out, it is effectively a Map<String, Map<Integer, List>>, where the 2nd level maps are really non-sparse arrays. If you chose a better data structure it would occupy less space and you could build it much faster. (I think you are right not to serialize it … since it looks like it might not be changed during game play.)

    A HashMap<Integer, Object> takes a LOT more space than an Object[].


    A better data structure would be Map<String, LevelMap> where LevelMap is something like this:

    public class LevelMap {
        private static final ArrayList<String> EMPTY = Collections.emptyList();
    
        private ArrayList<String>[] levels;
        private int firstLevel;
    
        public LevelMap(int firstLevel, int lastLevel) {
            this.firstLevel = firstLevel;
            levels = new ArrayList<String>[lastLevel - firstLevel + 1];
        }
    
        public static void addToTypeMap(String key, String value, 
                int firstLevel, int lastLevel) {
            LevelMap l = types.get(key);
            if (l == null) {
                l = new LevelMap(firstLevel, lastLevel);
                types.put(key, l);
            } 
            l.add(value, firstLevel, lastLevel);
        }
    
        public void add(String value, int firstLevel, int lastLevel) {
            ensure(firstLevel, lastLevel);
            for (int i = firstLevel; i <= lastLevel; i++) {
                j = i - this.firstLevel;
                if (levels[j] == null) {
                    levels[j] == new ArrayList<String>();
                }
                levels[j].add(value);
            }
        }
    
        private void ensure(int firstLevel, int lastLevel) {
            // Make sure that these levels are in the levelmap
            // If necessary, reallocate this.levels and adjust this.firstLevel
        }
    
        public String get(int level) {
            if (level < this.firstLevel ||
                level >= this.firstLevel + levels.length ||
                levels[level - this.firstLevel] == null) {
                return EMPTY;
            } else {
                return levels[level - this.firstLevel];
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on a project of porting an old solaris CL program to
Im working on porting some old ALP user accounts to a new ASP.Net solution,
I'm working on porting a large vb6 application to .NET. The current app is
I am working on porting an existing VB.Net application to Java, and could not
I am working on porting a VB6 application to .NET and one of the
I am beginner in android. I am working on porting ffmpeg to android and
I'm working on porting a Visual C++ application to GCC (should build on MingW
In the application I'm working on porting to the web, we currently dynamically access
I'm working on porting my open source particle engine test from SDL to SDL
We are currently working on porting an old VB6 application to WPF. The plan,

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.