New Posts  All Forums:Forum Nav:

Array limit in java?

post #1 of 4
Thread Starter 
I've got an int[] array in java, this is how it is created:
Code:
Scanner input = new Scanner(System.in);
int howtimes = input.nextInt();
int[] primes = new int[howtimes];

This array works for all sizes, ie entered numbers, up to around 178,000,000. At 179,000,000 or so it fails and gives me java.lang.OutOfMemoryError: Java heap space error. I'm not even putting anything into the array yet, but it is never created.

Basically,
Code:
int[] primes = new int[179000000]
doesn't work.

I'm using the Blue J IDE. I increased the heap size in its settings from default to minimum 256m and max 1024m. Does anyone have any suggestions as to why this error occours? And if it's not possible to fix this error, are there alternative storage methods to use? I need to be able to call them in the program at any time, so writing to a text file isn't great.

Cheers.
Mah rig 2.1
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 @3.0GHz MSI P43T-C51 Sapphire ATI HD 5850 1GB 4x1GB DDR2 
Hard DriveOSMonitorKeyboard
160GB, 500GB Seagate Windows 7 HomePremium x64 Dell SE198WFP x2 (19") Elephant KE-002 
PowerCaseMouse
Corsair TX650 HAF X ApaxQ AP-M98L 
  hide details  
Reply
Mah rig 2.1
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 @3.0GHz MSI P43T-C51 Sapphire ATI HD 5850 1GB 4x1GB DDR2 
Hard DriveOSMonitorKeyboard
160GB, 500GB Seagate Windows 7 HomePremium x64 Dell SE198WFP x2 (19") Elephant KE-002 
PowerCaseMouse
Corsair TX650 HAF X ApaxQ AP-M98L 
  hide details  
Reply
post #2 of 4
The number of dimensions of the new array must not exceed the number of array dimensions supported by the implementation (typically 255).

--Quoted from the java api:

http://download.oracle.com/javase/1.5.0/docs/api/

You could try an arraylist, but I don't know if that would work.
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
1100t Asus m4A78T-E HIS 5850 4G 
Hard DriveOS
60 SS, + 3T Windows 7 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
1100t Asus m4A78T-E HIS 5850 4G 
Hard DriveOS
60 SS, + 3T Windows 7 
  hide details  
Reply
post #3 of 4
It's because you don't have enough room in memory. Why the heck do you need 179 billion locations? It would be easier and faster if you used an arraylist.
    
CPUMotherboardGraphicsGraphics
i7 2600k Gigabyte P67-UD4-B3 GTX 580 GTX 580 
RAMHard DriveOSMonitor
Who cares? Intel SSD  Windows 7 Dell u3011 
MonitorPowerCaseMouse
Dell u3011 Seasonic x1200 800D G700 
AudioAudio
Xonar STX Beyerdynamic DT 990 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
i7 2600k Gigabyte P67-UD4-B3 GTX 580 GTX 580 
RAMHard DriveOSMonitor
Who cares? Intel SSD  Windows 7 Dell u3011 
MonitorPowerCaseMouse
Dell u3011 Seasonic x1200 800D G700 
AudioAudio
Xonar STX Beyerdynamic DT 990 
  hide details  
Reply
post #4 of 4
Quote:
Originally Posted by SS_Patrick;13285166 
It's because you don't have enough room in memory. Why the heck do you need 179 billion locations? It would be easier and faster if you used an arraylist.

This for sure... made things a lot simpler in programming back in HS, maybe you haven't learned it yet?

But it sure does help.
Dev0
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II x6 1090T @ 3.8 GHz ASUS M4A78-E 790GX PowerColor HD Radeon 7850 2 GB 2x4 GB DDR2 800 
Hard DriveOptical DriveOSMonitor
Crucial M500 240 GB SSD Samsung Super WriteMaster DVD Burner 20x Windows 10 Pro x64 ASUS VH226H 21.5" 
KeyboardPowerCaseMouse
Logitech PC Power & Cooling 500W Antec Three Hundred Modded Microsoft 3-Button Mouse 
Mouse Pad
Cheap Soft Mousepad 
  hide details  
Reply
Dev0
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II x6 1090T @ 3.8 GHz ASUS M4A78-E 790GX PowerColor HD Radeon 7850 2 GB 2x4 GB DDR2 800 
Hard DriveOptical DriveOSMonitor
Crucial M500 240 GB SSD Samsung Super WriteMaster DVD Burner 20x Windows 10 Pro x64 ASUS VH226H 21.5" 
KeyboardPowerCaseMouse
Logitech PC Power & Cooling 500W Antec Three Hundred Modded Microsoft 3-Button Mouse 
Mouse Pad
Cheap Soft Mousepad 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming