I need to initialize all the entries in a huge multi-dimensional array (10 * 25 * 200 * 1000) to a value. Is there any efficient way to do it rather than a 4 levels loop? Speed is my main concern. Thanks a lot for your suggestions.
Printable View
I need to initialize all the entries in a huge multi-dimensional array (10 * 25 * 200 * 1000) to a value. Is there any efficient way to do it rather than a 4 levels loop? Speed is my main concern. Thanks a lot for your suggestions.
Why would you need such an array ? I'm pretty sure you can find a work-around that would do the same job while being neater.Code:int huge_array[10][25][200][1000] = { 0 };
No 'efficient' way to set it to a specific value. But if setting the array to 0, Desolation's technique works.
Thanks guys. I need to set all the entries to a value not equal to zero, so I guess I am stuck.
If your array type is int, then memset over the entire thing should be safe:
If it's not an int, then individual assignment will be required, as you described.Code:memset(array, 123, sizeof(array));
If you used the initializer, it would be worse. The compiler would inline all 10*25*200*1000 = 50,000,000 (!!!) calls into your code. A for loop is probably all you have for now.
But Desolation is right; a better solution is probably just waiting to be discovered.
I hope you have lots of memory.Code:(10 * 25 * 200 * 1000) * 4 = 200000000
You should re-think your problem.
Have you thought of declaring it as a glolbal variable ?
My knowlege is a bit rusty.. if you declare it as a global variable it should automatically get initialized to 0.
Please correct me if i'm wrong. !!
It doesn't matter if you're right or not:Quote:
Originally Posted by Machoscorpion
Quote:
Originally Posted by alois_rone
Quzah.