Clearing Multidimensional arrays

Hi all,

I m hoping somebody can tell me which is the quickest way (in app performance) to clear multi dimensional arrays?

These arrays have up to 10 dimensions and each dimension has approx 8 indexes. The obvious way to clear (by clear i mean set to default value, in this case 0 because the arrays are doubles) is to run a few nested loops but doing this adds far too much time to the app. i also tried setting the object hold the arrays equal to a another object reference that had just been instantiated but this actually added even more time.

My final idea is to use an arraylist as the first dimension of the array andcalling .clear() on this. however this would require alot of rewriting of code so i havent tried it yet.

Any suggestions?
billyleoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
There's no quicker way to do it. Unfortunately Java has no direct memory access, so you can't zero out a block of memory.

You can reduce the amount of code you need to write by calling Arrays.fill

If you're already using multi-dimensional arrays, simply iterating them to zero out the memory is unlikely to be the main cause of performance problems.
0
sciuriwareCommented:
The quickest way of clearing an array of doubles is ........................ allocating a new array.

double[][] ddd = new double[12][45];  // Will contain 12 * 45   0.0 values.

;JOOP!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
Yes, that *could* be faster - time it and see
0
billyleoAuthor Commented:
Thanks to both of you for answering - i think i'll go with allocating a new array, i tried .fill but got all confused with the syntax
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.