I need a fast and efficient method to read a file, separated by a space, with numbers in an array. Files are formatted as follows:
4 6
1 2 3 4 5 6
2 5 4 3 21111 101
3 5 6234 1 2 3
4 2 33434 4 5 6
The first row is the size of the [rows columns] array. The following lines contain array data.
Data can also be formatted without a new line:
4 6
1 2 3 4 5 6 2 5 4 3 21111 101 3 5 6234 1 2 3 4 2 33434 4 5 6
I can read the first row and initialize the array with the row and column values. Then I need to populate the array with data values. My first idea was to read the file line by line and use the split function. But the second format presented gives me a pause, because all the data in the array will be loaded into memory immediately. Some of these files are located in 100 MB. The second way is to read the file in pieces, and then take them apart in parts. Maybe someone has a better way to do this?
source
share