Quote Originally Posted by Alimonster
Another thing I noticed: it seems like your loops are not cache friendly. When you have loops, you always want to do this:

for outer := ....
for inner := ...
access element[outer, inner]

Your map is a 2d grid of objects. Your method, it seems, is starting on the top left. Then, it goes down a column of tiles. Once it has reached the end of that vertical line, it goes to the next column and goes down it. You want the code to do the opposite - go left to right through a row of tiles, then down onto the next row, repeat. The cache is linear - it grabs the wanted value plus some more to the right. If you go vertically, the cache won't be very effective because all the pre-emptively grabbed values will not be next in sequence, meaning slower code .

I think (not having checked your code thoroughly, the above might not be the case).
It seems he has rows and columns mixed up. His for loops are correct, but his arrays are back-to-front.