Computing.Net > Forums > Programming > why 2d array java limited only this

why 2d array java limited only this

Reply to Message Icon

Original Message
Name: tvara
Date: November 19, 2003 at 00:30:54 Pacific
Subject: why 2d array java limited only this
OS: win2000/Linux
CPU/Ram: PIII 1000 RAM256
Comment:

I get state below when the size of 2D array more than 2875 x 2875

Exception in thread "main" java.lang.OutOfMemoryError
<<no stack trace available>>

my program must use array size many many but when i use JAVA i have
limited only this. If some one could help I would be very thank full

// This example code that when i change more array size than 2875 i will have
// state <<no stack trace available>>
class arr{
arr(){
JFrame f = new JFrame("arr");
f.setVisible(true);
f.setSize(200,200);

int n = 2875;
double [][] a = new double [n][n];
for(int i = 0;i<n;i++){
for(int j=0;j<n;j++){
a[i][j] = 1.234;
}
System.out.println(i);
}
}
public static void main(String[] s){
new arr();
}
}


Report Offensive Message For Removal


Response Number 1
Name: gpp
Date: November 20, 2003 at 05:57:17 Pacific
Subject: why 2d array java limited only this
Reply: (edit)

Does it run for a while before throwing that exception at you? It looks like you're just running out of physical memory. Java is extremely resource intensive to begin with.


Report Offensive Follow Up For Removal

Response Number 2
Name: DEEP_FX
Date: November 21, 2003 at 23:59:55 Pacific
Subject: why 2d array java limited only this
Reply: (edit)

Keep in mind that the elements in the array you are trying to declare take about 32MB of space.

2875 * 2875 * 4 bytes in an int = 33062500 bytes.

This is quite a large amount of ram. If you need to store such a large amount of information, consider writing the data to a file in increments.


Report Offensive Follow Up For Removal

Response Number 3
Name: Gagey
Date: November 23, 2003 at 19:40:09 Pacific
Subject: why 2d array java limited only this
Reply: (edit)

Actually DEEP_FX it's twice that figure (32M) again, the array is actaully of doubles not ints, but....

U could also try the -Xm memory switches when u fire up the jvm.

Start mem size:
-XmsNNN where NNN in bytes, kb or MB ie to start with 64M use -Xms64000000 or -Xms64000k or -Xms64m

Maximum mem size:
-XmxNNN (same a above for NNN)


Report Offensive Follow Up For Removal

Response Number 4
Name: Tvara
Date: November 27, 2003 at 22:27:08 Pacific
Subject: why 2d array java limited only this
Reply: (edit)

excute me what is -Xms64000000
and how i can use it


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: why 2d array java limited only this

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge