Java really isn't as slow as many would make you believe. http://kano.net/javabench/ http://www.idiom.com/~zilla/Computer...benchmark.html Certain operations can be slightly faster, whilst others are upto 10% slower.
int **mkmatrix(int rows, int cols) { int i, j, count = 1; int **m = (int **) malloc(rows * sizeof(int *)); for (i=0; i<rows; i++) { m[i] = (int *) malloc(cols * sizeof(int)); for (j=0; j<cols; j++) { m[i][j] = count++; } } return(m); }
return malloc(rows*cols*sizeof(int))
Pointers make optimization hard
Garbage collection- is it worse...or better? .... Consider what happens when you do a new/malloc: a) the allocator looks for an empty slot of the right size, then returns you a pointer. b) This pointer is pointing to some fairly random place. With GC, a) the allocator doesn't need to look for memory, it knows where it is, .... The big benefit of GC is memory locality. Because newly allocated memory is adjacent to the memory recently used, it is more likely to already be in the cache.