my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Alternatives to arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Alternatives to arrays

Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 191
Hi.

I have a program which needs to store data from text files (comprising of several Mb). I am storing this data into a number of arrays.

To do so, I am currently reading these files once to get the number of lines so that I can get the array length that will be required.

I am then reading the file again and storing this data as the file reader read line by line.

Is there is anything else other than arrays I can use which would mean I dont have to read the file twice? In addition, creating these large arrays are giving me the OutOfMemory heap problem.

Thanks


Moosey knows best
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11246
    
  16

well, if you're storing the whole thing in memory, i'm not sure changing the storage object will help much with the outofmemory error.

do you need to store the whole thing in memory? I would think that what you are doing with the data should determine what you use to store it...


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 191
Well basically Im ending up with a 2d array with dimensions over 20000 by 20000. The idea this is then put into a text file as a grid
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Okay, let's not waste people's time by having the same conversation twice. The other thread seems to have more info, so I'll close this one. Followups can go here please.


"I'm not back." - Bill Harding, Twister
 
Don't get me started about those stupid light bulbs.
 
subject: Alternatives to arrays