StreamBuffer vs. StreamBatchingBuffer?

Hi there,

I am fairly new to FreeRtos and Im trying to understand what to use for which purpose.

So I came across Stream Buffers and I saw that there are two creation functions ( xStreamBufferCreate and xStreamBatchingBufferCreate). In both I can set a trigger level, after which a reading taks will be unblocked. In the the documentation of the batching version it says:

The difference between a stream buffer and a stream batching buffer is when a task performs a read on a non-empty buffer:

  • A task that reads from a non-empty stream buffer returns immediately regardless of the amount of data in the buffer.
  • A task that reads from a non-empty stream batching buffer blocks until the amount of data in the buffer exceeds the trigger level or the block time expires.

However, in the xStreamBufferCreate description it gives this example:

xTriggerLevelBytes […] As another example, if a task is blocked on a read of an empty stream buffer that has a trigger level of 10, then the task will not be unblocked until the stream buffer contains at least 10 bytes or the task’s block time expires. […]

These seem to me like contradicting statements. Or how can I understand this?

In addition, they both use the same xStreamBufferReceive function. Is that correct?

Thanks for the help!

Hi @nathoid,
I’d be happy to clarify the differences between Stream Buffer and Stream Batching Buffer for you.

Regarding Stream Buffer, there are two primary scenarios to consider:

  1. When you invoke xStreamBufferReceive, if any data is present in the buffer, it will be returned, even if the amount is less than the specified trigger level.
  2. However, if the buffer is empty, the calling task will enter a blocked state. It will remain in this state until either the specified xTriggerLevelBytes are received or the task’s designated block time expires, whichever occurs first.

In contrast, Stream Batching Buffer operates slightly differently. It consistently waits for data until either of these conditions is met:

  1. The buffer accumulates the specified xTriggerLevelBytes of data, or
  2. The predetermined timeout period elapses.

Refer to issue and PR for detail discussion on GitHub.

Thank you.

So in essence, when reading an empty buffer, the two types behave exactly the same way. But upon encountering a non-empty buffer, StreamBatchingBuffer will block until the trigger level is reached, whereas the StreamBuffer is will not be blocked and return data, regardless of the trigger level.

Is that correct?

Yes, my understanding aligns with yours.