To further optimize this code see this page for info:
http://www.mulle-kybernetik.com/artikel/Optimization/
BTW, in the implementations posted of maxfunc and minfunc the min and max values aren't initialized, which is obviously wrong. I initialized maxval to zero in the code I posted but this is probably wrong also. These values should be initialized to either the minimum or maximum possible values or they should be initialized to the first value in the input array. It should also take into account the possibility of an empty array.
As for the initialations; this was simply a misswrite, in many other languages you can initialize two variables like that, at least when they are decleared right before...
If the arrays are large and performance is any part of your requirement, do not use Objective C arrays or objects in your inner loops. Obj C is completely unsuitable (until someone implements a lot more sophisticated compiler optimizations). The message passing overhead will consume the vast majority of your loop time. Compare it by benchmarking huge arrays if you don't believe me.
Use 1 dimensional C arrays:
float *a;
a = malloc(numRows * numCols * sizeof(float));
// check for a null array & don't forget to free a non-null array when done
item = a[myRow * numCols + myCol];
// if the compiler doesn't do it for you, hoisting the row multiply out of the inner loops is left as an exercise for the student.
Obj C was designed to be good for RAD code reuse, not for performance of number crunching. Use the object message paradigm only where it will buy you something; consider straight C otherwise.
I bellive you, but the problem is that i need the structure of a two dimensional matrix to do my math. as you point out, objC isnt made for number crunching, thats ok, but since objC is the only language i can use on the iPhone, i dont really have another option. Thanks for the tips though!
Adding a question here:
ok, so i have an nsmutablearray with nsdecimalnumbers in it. What i want to do, is to build a file locally on the Iphone that is readable in plaintext, and has 1 number on each line. (this means that im going to loop through the NSMutableArray, and for each NSDecimalNumber in it, i want to have one line in the file.
Ok, then after i have made this file, i need to get a hold of it on my mac, i.e. extract it from the iphone. I have found that one can upload to FTP server using objective-c. but i cannot understand how i do this, could someone please help me with some example code? this is very easy in C# for instance, and it is probably just as easy here, just that i dont understand how i do it.
all help is GREATLY appreciated!!
