[fpc-pascal] How to implement a circular buffer object in pascal?

Bo Berglund bo.berglund at gmail.com
Thu Sep 3 14:54:10 CEST 2020


On Thu, 3 Sep 2020 10:22:17 +0200, Martin Frb via fpc-pascal
<fpc-pascal at lists.freepascal.org> wrote:

>On 03/09/2020 10:09, Bo Berglund via fpc-pascal wrote:
>> I would like to create a buffer into which a thread can push incoming
>> data and the main thread can extract it for processing.
>> Data are coming from the serial port in a worker thread and should be
>> consumed by the main thread. The data is a byte stream.
>>
>> Are there any good examples available?
>> I have only implemented such systems in C on embedded platforms so it
>> is not pascal enough to easily port.
>>
>>
>Packager LazUtils
>unit LazCollectionss
>
>TLazThreadedQueue
>

So what you meant is that it is part of Lazarus already?
I found it here in my local installation:

~/dev/lazarus/2.0.8/components/lazutils/lazcollections.pas

When I added lazcollections to the uses clause of my test project it
loaded fine when right-clicking and selecting "Find Declaration.."
So it is clearly in the search path for Lazarus. :-)


Now to my question:

Is there some *example* around for using TLazThreadedQueue as a
circular buffer?
In the examples dir are only examples for LazUnicode and
LookUpStringList...
And when reading the sources I cannot really say I understand what it
does or how it works.

Is it even applicable for storing data such as a sequence of bytes
arriving via a serial port?
The names PushItem and PopItem really suggest it works like a LIFO
buffer rather than a FIFO buffer, which is what I need...

LIFO: Last In First Out, like how a stack works
FIFO: First In First Out, like a tube where the items reside for a
while but come out in orderly sequence.


-- 
Bo Berglund
Developer in Sweden



More information about the fpc-pascal mailing list