-
buffers... can u help?
This is for a friend of mine, who's too lazy to join a forum..
How do you use a circular buffer to store an array of data?
That's his question.
Can you guys give some ideas on how to do this, I'll just do a copy and paste and printout and shove it in his face.
thanks
-
implementing a queue maybe?
Code:
int buffer[10]
buffer[(offset+X)%10]=1;
++offset;
buffer[(offset+X)%10]=2;
-
A circular buffer is a linked list with a slight twist.
The 'first' element in the list points to the last as the previous element, and the last element points to the first element as the next. This code creates the buffer
Code:
typedef struct x{
struct x *prev;
char data[100];
struct x *next;
};
struct x m[100];
for (i=1;i<100;i++){
m[i].prev = &m[i-1];
m[i].next = &m[i+1];
memset(m[i].data,0x00,sizeof(m[i].data));
}
m[0].next=&m[1];
m[0].prev=&m[100];
m[100].next=&m[0];
m[100].prev=&m[99];
memset(m[0].data,0x00,sizeof(m[0].data));
memset(m[100].data,0x00,sizeof(m[100].data));
-
Surprisingly, I understood that myself.
OK, Thanks. just what he needed.