Buffers Flashcards

1
Q

Linear arrays

A

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//

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Stack (Last-in, First-Out)

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Queue (First-in, First-out)

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does interrupt safety refer to?

A

The writing of code that can be executed safely in the presence of interrupts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you ensure interrupt safety?

A
  1. Disabling the interrupts all together
  2. Use atomic instructions (completed in one step without the possiblility ot be interrupted)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly