Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Default Lowering Memory usage

    Okay guys, I'm trying to make a simple animation program, so I have these this in my code to hold the data for what has been "painted" to each frame
    Java Code:
    // Holds the artwork, max of 1000 frames, and 10,000 possible cells for each frame
    static public cell cells[][] = new cell[1000][10000];
    
    // The cell class
    static public class cell {
    	public short x;
    	public short y;
    	public byte value;
    		
    	public cell(short xVal, short yVal, byte val) {
    		x = xVal;
    		y = yVal;
    		value = val;
    	}
    }
    Right now, when I run the built JAR, the Task Manager says I'm using 76,244KBs, witch roughly equates to a usage of 74.45MBs. I have 2GB of Ram, but I realy don't like the number of MBs in use.

    Any tips?
    Good with: C/C++, DarkGDK, PHP, MySQL
    Current reading: The Linux Programming Interface

  2. #2
    snotmare is offline Member
    Join Date
    Apr 2011
    Posts
    34
    Rep Power
    0

    Default

    Do you really need to keep a reference to each cell? Can you make use of your cell and then discard it when you're done?

    I suppose you might need to post some more of what you're using your cells for.

  3. #3
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Default

    Well, what I'd like to do is when the user adds a value to the cell, or adds a new frame, it then adds that cell/frame into the memory.

    But I know here at the beginning of my program is when the memory is getting populated, I'd rather populate when I need to.
    Good with: C/C++, DarkGDK, PHP, MySQL
    Current reading: The Linux Programming Interface

  4. #4
    snotmare is offline Member
    Join Date
    Apr 2011
    Posts
    34
    Rep Power
    0

    Default

    Are you creating somewhat of a canvas like you would have in a paint program, where a user draws on to the canvas and you have to set the value for each pixel?

    You need to provide more information for what you're trying to do. I wonder if you really need to store 10000000 cells all at once, but I can't tell you for sure until you fully explain what you're trying to do :).

  5. #5
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Default

    Yeah, it essentially is a painting program. I'd really prefer not to provide much more code.

    I'm just wondering if there is anything I can do to create dynamic memory when it's needed, not at the initialization of a program.
    Good with: C/C++, DarkGDK, PHP, MySQL
    Current reading: The Linux Programming Interface

  6. #6
    snotmare is offline Member
    Join Date
    Apr 2011
    Posts
    34
    Rep Power
    0

    Default

    Well, with the info you've shared, about all I can suggest is that you create your array, but not fill the elements until you need them. Look into the concept of "lazy loading". Essentially, it's like this...

    Java Code:
    private MyClass value;
    private MyClass getValue(){
       if(value == null){
           value = new MyClass();
       }
       return value;
    }

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,312
    Blog Entries
    7
    Rep Power
    24

    Default

    What are you going to do with all those Cells? Display them one by one?

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. Suggestions needed for decreasing memory usage
    By TheEnemy in forum Advanced Java
    Replies: 1
    Last Post: 02-14-2011, 06:12 AM
  2. Memory usage
    By Moon_E in forum New To Java
    Replies: 20
    Last Post: 07-09-2010, 10:53 PM
  3. heap memory usage anomaly?
    By jon80 in forum Threads and Synchronization
    Replies: 1
    Last Post: 06-30-2009, 06:56 AM
  4. Replies: 2
    Last Post: 12-07-2008, 07:13 PM
  5. JVM memory usage
    By lardum in forum New To Java
    Replies: 7
    Last Post: 06-26-2008, 03:30 AM

Posting Permissions

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