Re: Access Shared Buffers
There are several ways. Yes, you could use locking primitives.
You could go lock-free and keep allocating more buffers and treat-them as write-once and leave the reading code to release the memory.
You could use a circular buffer where you have two pointers into it, one write, one read. All you have to do is ensure that you never write past the read buffer and then you don't need any locking or synchronisation between the two threads.
What's best? That depends entirely on you and your scenario. I would pick the approach that you understand best so you've got the best chance of getting it right.
Re: Access Shared Buffers
Thanks
The locking primitives, was my first thought, but i'm affraid while locking it, i loose some data...
Circular buffer it's complicated, i don't know how much data I'll have in the buffer, and for every buffer i can have different quantities.
Using different buffers every time, it's a possibility I'll take a look to this, something like duble bufferring... :)
Re: Access Shared Buffers
Circular buffers aren't that complicated at all, and can be quite fast.
How fast is the data coming in? With memory size in computers, you could have several Mb buffers. If you have a 1Mb buffer, and you are reading from it every 100mS or so, that's 10mbps. However, that's a massive amount of data; I can't imagine you have that much coming in.
The other option is dual buffers/double buffers. You still run the option of loosing data as your buffers have to be big enough, regardless of the methodology you use.
Re: Access Shared Buffers
I didn't say that they're complicated... I only said, that i don't know the amount of data i'll have.
The data, theoretically it's coming in some channels at 8 messages (each one can vary from 3 bytes to 12 bytes), per second (125ms/each) top, but i can have situations that nothing is received, wireless, cant control...
The size of the buffer isn't a problem, not so much data.
But anyway I already made some tests with double buffering and looks like this is the best path...
THanks