Results 1 to 7 of 7
Thread: Lowering Memory usage
- 04-25-2011, 08:59 PM #1
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
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.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; } }
Any tips?Good with: C/C++, DarkGDK, PHP, MySQL
Current reading: The Linux Programming Interface
- 04-25-2011, 09:13 PM #2
Member
- Join Date
- Apr 2011
- Posts
- 34
- Rep Power
- 0
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.
- 04-25-2011, 09:32 PM #3
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
- 04-25-2011, 09:52 PM #4
Member
- Join Date
- Apr 2011
- Posts
- 34
- Rep Power
- 0
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 :).
- 04-25-2011, 10:20 PM #5
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
- 04-27-2011, 07:40 PM #6
Member
- Join Date
- Apr 2011
- Posts
- 34
- Rep Power
- 0
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; }
- 04-27-2011, 07:53 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,386
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Suggestions needed for decreasing memory usage
By TheEnemy in forum Advanced JavaReplies: 1Last Post: 02-14-2011, 05:12 AM -
Memory usage
By Moon_E in forum New To JavaReplies: 20Last Post: 07-09-2010, 10:53 PM -
heap memory usage anomaly?
By jon80 in forum Threads and SynchronizationReplies: 1Last Post: 06-30-2009, 06:56 AM -
should i use arrays or hashtables for less memory usage?
By arnab321 in forum New To JavaReplies: 2Last Post: 12-07-2008, 06:13 PM -
JVM memory usage
By lardum in forum New To JavaReplies: 7Last Post: 06-26-2008, 03:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks