Buffers Flashcards
Linear arrays
Any element is directly accessible via its array index
N = 100
buffer[N] (creates buffer of size N)
buffer[2] = 7.0 //third position in array assigned value of 7.0//
y = buffer[1] //y is assigned the value of th enumber at position 2//
Stack (Last-in, First-Out)
Access the top of the ‘stack’ only
push(13.0) //pushes 13 to the top of the stack
x = pop() //x equals the number of the top of the stack and this number is now removed from the stack
Queue (First-in, First-out)
- Access only to the oldest value in stack
- Requires two index pointers for the head and tail of the stacks
- New elements always added at the tail
enqueue(5.0) //adds value of 5 to the end of the stack. Tail moves along by one. If you have 8 bit size and tail was at 7 already, new tail wraps and becomes index 0//
x = dequeue() //x equals the oldest value that was at the head. This value comes out of the buffer and the tail increments by one
What does interrupt safety refer to?
The writing of code that can be executed safely in the presence of interrupts
How can you ensure interrupt safety?
- Disabling the interrupts all together
- Use atomic instructions (completed in one step without the possiblility ot be interrupted)