Open buriansandor opened 3 months ago
Hello. You mean you want to take a pointer on a ring buffer object ?
best regard
My idea is that I want to get it as a function parameter as a pointer. How can I do this?
Do it as you do for any other data type but I suggest you pass it as reference instead of pointer.
void myFunc(RingBuf<byte, 20> &ioBuf);
myFunc(myBuf);
assuming myBuf
is declared as follow: RingBuf<byte, 20> myBuf;
A full example with both reference and pointer RingBufAsRefPtr.zip
Ok, thank you! Now I understood. I want to access it from two different threads on ESP32, this is why I think it is better as a pointer.
Hello.
You can access it on different threads (I suppose you mean FreeRTOS tasks) as variable. Using a pointer will not make any difference because in the end the race condition will occur in the buffer storage, not in the way the code accesses the storage.
However, if you use you have to use a semaphore to prevent preemption. A binary semaphore is ok. Your code hase to take it before calling any function of the ring buffer and release it after.
Hi, I would like to access this RingBuffer as a pointer. Does this solution have such an option?