D - Circular buffers
- Mark Evans (18/18) Sep 16 2002 Should circular buffers be part of the D language or library? They are ...
Should circular buffers be part of the D language or library? They are terribly useful in any sort of communications or embedded project. Many DSP chips sport built-in circular buffer addressing to handle real-time data filtering. D would be doing us favors just to offer standard pointer arithmetic like that (a new pointer type). The best kind of circular buffer is a modification of the textbook type. Those have a hard wrap-around at the end. My technique is to keep the hard wrap-around, but soften it with a "spillway" abutting the end of the buffer. This spillway is periodically emptied by copying its data up to the top of the buffer. The circbuf therefore has a "nominal size" and a "true size" (the latter includes the spillway). The circbuf behaves as one expects, but with the added benefit that runtime calls (printf, sscanf, etc.) still operate properly at the end of the buffer. I am day-dreaming about the D garbage collector automatically copying the spillway when its sniffer detects the necessity... Ah Walter we sure know how to make up work for you, don't we... <g> ... just the stuff my dreams are made of, Mark
Sep 16 2002