1

I'm running into this compiler error due to my extremely large lookup table based on this definition:

//92 X 182 array
private static final double[][] lookUpTable = new double[][]
{
    { numbers....}
};

As i understand it, dividing it up is a solution, but it would be extremely difficult to split this array up accurately. I also believe i could move it out to a file, but i don't know if i could format it in a way to help me, plus i don't want file reads every second. Are there any other suggestions to help me get around this?

Ridcully
  • 23,362
  • 7
  • 71
  • 86
Jason
  • 2,147
  • 6
  • 32
  • 40
  • I guess you refer to `Java lookup table exceeds 65535 limit` as compiler error. I wouldn't have understood this from your question, hadn't I run into the same rare error a few weeks ago --- My solution in the end was to read the values from a file at the start of the program once. – Ridcully Sep 05 '12 at 19:49
  • Yeah, it is related to the 65535 issue. I struggle constantly with the ability to exactly describe my problem in a clear manner. – Jason Sep 05 '12 at 19:54
  • I edited the title to make it a bit clearer. Hopefully it draws more attention now. – Ridcully Sep 05 '12 at 19:57
  • thanks. I'm out for the rest of the day, so i will check in tomorrow morning. I am definitely leaning towards the resource file. – Jason Sep 05 '12 at 19:59

3 Answers3

5

Convert your table to a file, embed the file as a resource, read it once in a static initialization block, and store it in a lookUpTable array. It will not be distinguishable from an array initialized through an aggregate, except there would be no 65535 limit. Storing in a static variable will help you avoid "reads every second".

As far as the format is concerned, you can put each row of the matrix in a separate line of the resource file. Reading and maintaining this file would be simple, because there would be no other mark-up around your numbers.

Here is a link to an answer explaining how to read a file from a resource.

Community
  • 1
  • 1
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
1

Read the file once on demand.

As you have a table/matrix, I suggest having one line per row. Read each line and split the numbers and parse them individually.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
0

You could keep the rows in a string (thus reducing the number of objects for java to handle) as comma separated values, and on program start, split each row and so build up your table of longs.

Ridcully
  • 23,362
  • 7
  • 71
  • 86