??? 09/20/06 08:19 Read: times |
#124651 - Reasons to Waste Machine Cycles Responding to: ???'s previous message |
Erik said:
I am giving an example of serial data being stored in various places after receipt and verification.
we have a "modular by russ" serial module to get, say 1024 bytes from serial we need to do this to load a buffer for (index = 0; index <1024 ; index++) { SpecificBuffer[index] = getCharacter(); } if we program 'small embedded' instead of 'PC' we do this for (index = 0; index <1024 ; index++) { SpecificBuffer[index] = GlobalSerialBuffer[index]; } and have saved something like 20*1024 instruction cycles. Ok, the approach by Russ may be 'prettier', 'safer' or whatever, but WHY waste 20k instruction cycles in an environment that is definitely not 'resource rich'. This is a good example. When you say that the received and verified data needs to be "stored in various places", I think you're implying that there are several different SpecificBuffer[]s, and that each one will have a dedicated loop like the one in your "small embedded" example to copy contents of the GlobalSerialBuffer[] to the corresponding SpecificBuffer[]. If I've correctly understood what you're suggesting, then there are several points to be made:
Erik said:
There is nothing hindering a modular approach by using global variables i.e. I have all handling of serial in ONE module with nothing else, but to make getting a character a means of processor overload is ridiculous. This is just plain wrong. Simply grouping related functions together into files is a step in the right direction, but that by itself doesn't buy you much of anything beyond making it easier to remember which file contains which functions. The big point of modular programming is to make the modules independent, 1) so that changes in one of them don't break one or more of the others, and 2) so that you can extract a module from one project and reuse it elsewhere without having to drag along half of the first project to just to make it work. You simply cannot do these things if you allow your modules to muck around with each others' data. -- Russ |