×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2003
    Location
    United Kingdom
    Posts
    49

    What happens to a JAR file?

    Hi,

    When an app is ran on a phone, is the complete JAR file decompressed to the phones internal memory or just the class files?

    Also, I am correct in assuming that final data does not use heap space?

    I ask these questions, because I have a number of maps for a tile map based game and I am trying to figure out the most space conscious way of loading maps into memory. I thought that the easy way would be to simply create a number of final arrays with the data in, but a handful of maps could quite easily begin to add up to 20-30k of final data. On the other hand I could put the maps into the JAR file and load them at run-time, but if the complete JAR file is decompressed when the game is loaded then that would be pointless.

    Which method would be best at conserving memory?

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    Putting them in resources in the jar sounds more space conscious to me.
    Final data uses heap space the same as all other data. If it's final static then it will be part of the class loaded into the heap, and if it's just final (and not static) then it will take up heap space in every instance of the class you create.
    On top of that, when you declare a static array like this:
    Code:
    static final int[] array = {1,2,3,4,5,6,7,8,9,10}
    the code will compile into something like this:
    Code:
    static final int[] array = new int[10];
    array[0] = 1;
    array[1] = 2;
    // ...
    array[9] = 10;
    So not only you don't save any heap space with the array (since it is stored in the heap), you also make your class bigger with all that extra code (and the class also takes up space from the heap).
    If you save it in a resource, then you'll need a method to take it out of the jar, but that same method will be able to expand all of the arrays (instead of having that code listing above of every one of the arrays). So if you have more than one or two of these arrays it is much better.

    When an app is ran on a phone, is the complete JAR file decompressed to the phones internal memory or just the class files?
    This would be implementation dependant, but in most cases I don't think the whole jar is uncompressed.

    shmoove

  3. #3
    Registered User
    Join Date
    Mar 2003
    Location
    United Kingdom
    Posts
    49
    Thanks for that

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×