begin  quoting Wade Curry as of Fri, Sep 29, 2006 at 10:52:13PM -0700:
> Andrew Lentvorski([EMAIL PROTECTED])@Fri, Sep 29, 2006 at 06:19:33PM -0700:
> > Stewart Stremler wrote:
> > 
> > >I used to have a directory full of simple C data structures -- 
> > >singly-linked list, doubly-linked list, hashtable, binary tree,
> > >etc. -- but I seem to have lost that directory.
> > 
> > Circular buffer is what I was looking for.
> 
> I understand what all of those datastructures are except the
> circular buffer.  What is it?  More importantly, what kinds of
> things is it good for?

It's a fixed-sized fifo. You use 'em in space-constrained systems to
buffer input using a fixed amount of memory, without having to shift
a lot of data around.

Out of idle interest, I bashed one out in C today to see what's
involved[1][2].

Andrew's right... unit-testing in C is annoying.  It might be less
so if I had a good framework to use... but without reflection or
introspection, a lot of the "convenient" features just aren't there.

(And I think what I implemented is a "ring buffer", but I didn't look
anything up to be sure.  I was just having fun writing C code.)

See http://www.stremler.net/temp/circular_buffer.tar for my
quick-and-dirty C "circular buffer" backed by an array. YMMV,
etc. etc.

[1] No autoconf, just an uber-simple makefile. Minimal documentation.
Minimal unit testing. Ugly names. But it's public domain. Take it,
add documentation, unit tests, a better naming convention... 

[2] I'm afraid it has been a long time since I've created any C code
from scratch... feedback on the code would be welcome. 
-- 
_ |\_
 \|


-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to