How to manage Full Circular Queue event?

Technology CommunityCategory: QueuesHow to manage Full Circular Queue event?
VietMX Staff asked 3 years ago

When this situation occurs, your queue is full. You have a few options when to deal with new items that can be pushed:

  1. discard the pushed event: only when some other item is popped can now items be pushed again. Neither head nor tail is updated.

    Example: Think of an event queue that has filled up, new requests are simple ignored.

  2. discard (pop) the oldest event on the queue: in this case you update both the head and tail pointer one place.

    Example: buffering incoming image frames from a webcam for processing. For a ‘live’ feed you may prefer to discard the older frames when the processing has a hickup.

  3. create a bigger queue: that is, allocate more memory on the fly

    Example: you use a circular queue since it an efficient implementation that doesn’t require memory allocation most of the time when you push items. However, you do not want to loose items on the queue so you allow reallocating more memory once in a while

What the right action is depends on your application.