0

I have a 3-D array [8][8][1002], which remains static with every run(values don't change). Each page of array contains binary combination (8x8 matrix).

The array will take a lot of time to load, which I want to avoid.

Any way to reduce the time taken?

Or any other data structure may work effectively faster?

UPDATE:

The initialization of array is done by exhaustive method :

Loop1 for i:
  Loop2 for j:
   Loop3 for k:
   array[i][j][k]=1 //or 0 some logic

By loading, I mean array initialization.

10
  • If it's static why would it take any time to load? Commented Feb 6, 2014 at 14:52
  • 1
    How are you loading the array? Commented Feb 6, 2014 at 14:52
  • What's the Java tag for? Commented Feb 6, 2014 at 14:58
  • If you don't want it to take any time then initialize it with immediate values. This makes your code larger (much), but eliminates the issue you're discussing. You can use a simple code generator to output the init code. Loading it from a file might be faster as well, you could serialize it. Commented Feb 6, 2014 at 14:59
  • 1
    Then I can bet a cookie that your real bottleneck is not in the array loading :). I recommend you to use a profiler for your application like VisualVM that already comes since JDK 6. If you're using JDK 7 u 40, you can use Java Mission Control, which comes with this and later distributions. Commented Feb 6, 2014 at 15:40

2 Answers 2

1

If you want to initialize with 0, so you don't need to write any init code, before default value is 0 when you creating an instance of array:

final int[][][] array = new int[1][1][1];
System.out.println(array[0][0][0]);

The result is: 0

Sign up to request clarification or add additional context in comments.

1 Comment

Hmm interesting, so have to work only on selective ones.
0

If speed is a must, try declaring the array as final, and initialize it while you create it. That'll take a lot of code but will probably be faster.

final int[][][] array = {...}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.