electroRF
Member
Hi,
I got a nice question which is also related to the other topic on Circular Buffer, and I'd love hearing your ideas on it
You got a 8KB buffer which you logically divide into 2 equally-sized parts, A [0-4KB), B [4KB-8KB).
You start running circularly on that buffer, each time writing few bytes into it (different amount each time, but not more than few hundreds of bytes).
How would you spot the moment in which you moved from one section to the other?
e.g. you were @ address (&Buff[0] + 4090), which is in Section A, now you wrote 10 bytes, therefore you moved to Section B @ address (&Buff[0] + 4100).
How would you tell at the end of that writing, that you're now in a different Section then you were before? (e.g. you're now at section B, while you were at section A).
The obvious way would be:
Would you do it in another way?
I got a nice question which is also related to the other topic on Circular Buffer, and I'd love hearing your ideas on it
You got a 8KB buffer which you logically divide into 2 equally-sized parts, A [0-4KB), B [4KB-8KB).
You start running circularly on that buffer, each time writing few bytes into it (different amount each time, but not more than few hundreds of bytes).
How would you spot the moment in which you moved from one section to the other?
e.g. you were @ address (&Buff[0] + 4090), which is in Section A, now you wrote 10 bytes, therefore you moved to Section B @ address (&Buff[0] + 4100).
How would you tell at the end of that writing, that you're now in a different Section then you were before? (e.g. you're now at section B, while you were at section A).
The obvious way would be:
C:
char section = 'A'; //Global pointer, initialized to 'A', since we start writing the buffer from the beginning, at section A.
//ptr is the running pointer. it can be assumed it's always within the Buffer's range
if ( (ptr < &Buff[0] + 4096) && (Section == 'B') )
{
section = A;
//Moved to a different section! do your thing here.
}
else if ( (ptr >= &Buff[0] + 4096) && (Section == 'A') )
{
section = B;
//Moved to a different section! do your thing here.
}
Would you do it in another way?