• C

# what circ buffer?

what circ buffer?
simple source..
plz...
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
circular buffer means if u r at the end of the buffer, and u want to insert more data in the buffer then it will go to the start of the buffer

taking a simple example

char a[5];

if u push "hello" to this
then it will fill up the array..
and if u push further data .. say "zz"
then array will look like
"zzllo"

i dont think if any standard implementation gives u circular buffer .. u'll have to implement on ur own .. or use someone else implementation
0
Commented:
http://www.cs.utk.edu/~calloway/prg/cq/
simple circular implementation for you
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
circ buffer = queue first in first out where you put the data in an array that is managed in circular fashion.
Ah lets take look at the example.

buffer [data1][data2][     ][    ][    ] MAX_BUFFER

You put the data in the head.
Each time the data is put, the head is increased. After the head reached the MAX_BUFFER, the head is rolled back to ZERO ===> thats why they call it circular. If the head reached the tail again (from the back), thats mean the buffer is full.

On the other side, you get the data from the tail and increased the tail. If the tail == to the head, thats mean the buffer is empty.

Ahhh .. look at the code and learn bys.

#define MAX_BUFFER 10;
struct {
buffer[MAX_BUFFER];
} CB;

// On empty state, head == tail
int Init(CB* cb)
{
}

int Put(CB* cb, int data)
{
if (new_head == cb->tail) return 0; // FULL
}

int Get(CB* cb, int data)
{
int old_tail = cb->tail;
if (old_tail == cb->head) return 0; // EMPTY
cb->tail = old_tail + 1;
if (cb->tail >= MAX_BUFFER) then cb->tail = 0;
return cb->buffer[old_tail];
}

main()
{
CB cb;

Init(&cb);
Put(&cb, 1);
Put(&cb, 2);
Put(&cb, 3);

printf("%d ", Get(&cb));
printf("%d ", Get(&cb));
printf("%d ", Get(&cb));
}
0
OwnerCommented:
Nothing has happened on this question in more than 10 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to

jmcg
EE Cleanup Volunteer
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.