Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: Circular buffers

2004-03-05 by embeddedjanitor

This method has one problem.
If the buffer fills up, then previous contents will get lost.
ie. If you add 1024 bytes before taking any off then onpointer will 
be the same as offpointer and the whole buffer will be lost.

It does, however, look threadsafe (well interrupt safe anyway) and 
will be fine so long as you don't get too far behind.


--- In lpc2000@yahoogroups.com, Peter Kuhar <peter.kuhar@g...> wrote:
> I belive this is te best way to do it. Using linked list is to
> procesor and memory consumnig. If you use add byte only in interrupt
> rutine and getbyte only in main program it's considered to 
be "thread
> safe"
> > Circular buufers are a technique not routines
> 
> > Typical psuedocode:
> 
> >     buffer[1024];
> >     int onpointer=0,offpointer=0;
> 
> >     procedure addbyte(data) {
> >           buffer[onpointer]=data;
> >           onpointer++;
> >           onpointer= onpointer & 1023;
> >     }
> 
> >     function getbyte() {
> >           res
> >           if (onpointer==offpointer)
> >                  return 0;   // no data available
> >           res=buffer[offpointer];
> >           offpointer++;
> >           offpointer=offpointer & 1023
> >           ret res;
> >      }
> 
> > onpointer alwasy points the the first avaliable free space. 
offpointer
> > always points to the next item avaliable
> 
> > Owen
> 
> >>Message: 11
> >>   Date: Wed, 3 Mar 2004 22:59:44 -0800
> >>   From: "Curt Powell" <curt.powell@s...>
> >>Subject: Circular buffers
> >>
> >>Can someone point me to some circular buffer routines?
> >> 
> >>TIA,
> >> 
> >>Curt
> >> 
> >>
> >>  
> >>
> 
> 
> 
> 
> 
>  
> > Yahoo! Groups Links

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.