I have some feeling that people will try to beat me on the head and say: "You should not do this!" (and I am fully aware of this fact); however, here is my problem:
Suppose you have the following C ++ code:
EDIT: I think I have not shown enough of what I'm trying to do, although most of the answers were excellent. So here is the edited version of my code. The main thing is that at each iteration I still need to use an array of vales values, which is a submatrix of x , and not just one value in the index:
unsigned int n = 2000; // or any other number for that matter double * x = new double[n]; double resultArray; // fill array with meaningful data // do all kinds of initializations for( int i=0 ; i<someNumber ; ++i ){ //someNumber ~ 1900 // do some stuff for (j=0 ; j<someSmallerNumber ; ++j){ //someSmallerNumber ~ 15 resultArray[j] = x[j] * someFunction(resultArray[j]); } ++x; //increment pointer to the first element of the array // do some more stuff }
EDIT: The reason I use ++x in the outer loop is because if I were to use x[outerIndex+innerIndex] instead of just x[innerIndex] , I would still have many more additions to iterate, and this is a heavy algorithm algebra, so I'm trying to squeeze some performance out of it.
I would like to point out that my algorithm never tries to read non-existent memory. This is just processing speed when I try not to recount the current array index more times than I need. This works great, and I am pleased with that.
Now I am trying to implement a similar algorithm in Java (and Java in not quite my area of ββexpertise). However, I know that Java really does not give you access to pointers and treats everything as an object. My question, of course, is an efficient way to execute the equivalent of ++x , where x is the address of the first element of the array in Java? Is it possible to remove the first element of the array? Are there any good quick search algorithms if they are not part of the built-in manipulation of Java arrays?
Thanks in advance! =)
source share