Olin Lathrop wrote: >>> A common method on a big system for reading a text protocol is to >>> buffer up >>> a line at a time, then parse it. However when you really look at the >>> parsing algorithm, most of it is sequentially reading the characters >>> in the >>> line. With a little thought, you can usually eliminate or greatly >>> reduce the buffer by processing the stream a byte at a time in the >>> first place. >> >> There are two problems I see with this: >> >> 1. It is less straightforward. > > Huh? I really can't imagine why either chunk processing or byte stream > processing is inherently more "straight forward" than the other. Byte > stream processing lends itself particularly well to multi-tasking. The > task > runs in a infinite loops getting the next opcode byte, dispatching to the > routine for that opcode, which may then branch further depending on > command > options, etc. [snip] Olin, how is this "reusable"? Your "opcode dispatch" logic is superglued to your UART code. > On a big system, there can be relatively high overhead just getting into > and > out of the system call to get data, so getting a bunch of data at a time > is > actually more efficient. This isn't the case on a PIC. On a PIC the > "usual" get-buffer method is less efficient. My main point, however, is > that with the right mindset you can embrace the byte at a time phylosophy > and write more efficient and just as elegant, reusable, maintainable, > cures > cancer, etc, code as with the other mindset. I don't see how. Of course sometimes it's necessary to do it the way you describe, because you don't have a choice (e.g., you don't have enough clock cycles or RAM). However, this approach basically forces you to write code that is inherently incohesive and tightly coupled. > It just takes a different way > of thinking about the whole problem, which apparently isn't easy for > people > that grew up calling ReadFile. [insert a counter-dig here] :o) Vitaliy -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist