oh, one annoyance - files created by lua don't get their date/time set correctly.
use os.utime
http://chdk.wikia.com/wiki/LUA#LUA_standard_libraries:_io.2C_os_and_string and os.date
I suspect the reason the firmware doesn't do this by default is for efficiency, since it requires an extra sector write.
As for reading/writing large blocks, I'd say there's only about 4 values worth considering:
1) 1 byte at a time. Very slow, but no memory issues because there are only 256 unique 1 byte strings
2) 1 hardware sector at a time (512 bytes AFAIK)
3) 1 FAT sector at a time (variable, 64K or less)
4) 32 KB (size of Fut IO buffer)
Beyond the last option, I doubt you will see any increase in performance. If the performance between 2) and 4) is equivalent, I'd stick with 2.
a big part of my refactoring of sunsetF15 was to localize as many variables as possible. perhaps there are negative consequences to this but its good programming practice.
Making
variable local does not force the
values it referenced to be collected when the variables go out of scope. The garbage collector acts on values, not variables. Using locals is fine, but if you want to understand memory usage, you have to understand how the garbage collector operates.
As a start, I'd suggest logging the "count" value from collectgarbage. Then try forcing a full collection, and logging the new count value and free RAM. If actual memory usage is still going up, there is a problem. Of course, you will probably get quite a bit of fragmentation from long running lua scripts.