Stewart Stremler wrote:
>..
> 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. 


Hmmm, your code is storing pointers to the data, which I _don't think_
is the usual need (especially for interrupt server routines, for example).

It's interesting, I think that we both implemented a required-hole
method for keeping full and empty from being confused, and incidentally
avoid any critical section worries.

Other than the data vs pointer thing, you expressed in indices what I
did with pointers, and I choose a slightly roundabout pointer
initialization (using pLastPut instead of pNextPut).

Your code & coding style is definitely more polished and finished. The
encapsulation as an object gets extra-credit pizzas!

It seems to me that you might have freed the cbuf if the data malloc
failed.  Oops, need one more unit test for memory leak, eh? I didn't
take the time to review your tests, so I can offer no feedback there, sorry.

I might explain my choice of interface returning true/false and
requiring a buffer on the get. NULL on failure is certainly a time
honored tradition, but I believe one can argue against it. No so much
here as in things like getc() where the return type has to be butchered
to be able to indicate failure. But anyway, I kind of like making the
user pass his own buffer which I fill. It perhaps calls attention to the
 need to test the return value.

Regards,
..jim

PS, how did you find my code? Bicarb-time?
..j


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

Reply via email to