|
-
Mar 26th, 2002, 03:26 AM
#1
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
-
Mar 26th, 2002, 04:21 AM
#2
transcendental analytic
implementing a queue maybe?
Code:
int buffer[10]
buffer[(offset+X)%10]=1;
++offset;
buffer[(offset+X)%10]=2;
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Mar 26th, 2002, 10:54 AM
#3
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));
-
Mar 26th, 2002, 09:43 PM
#4
Surprisingly, I understood that myself.
OK, Thanks. just what he needed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|