Computer Science Canada [tutorial] restoring array quickly |
Author: | vlovich [ Sun Jun 01, 2003 2:57 pm ] | ||
Post subject: | [tutorial] restoring array quickly | ||
I came across this when I was doing a game. Basically, I have a screen class. This screen class allows me to cut out rectangles and also check if a given rectangle can fit in the remaining screen. The problem was that every time I had to clear the screen, I had to have two nested for loops and go through each element and set the default value. A simpler workaround turns out to be:
This doesn't actually speed up the original clear, but all the consecutive clears should be a bit faster since the compiler should copy one array into another which should be faster than setting each element individually. If anyone has some speed tips to speed up the original clear, I'd be glad to hear them (such as accessing the array in memory directly and sequentially setting its value) |