Results 1 to 5 of 5

Thread: Access Shared Buffers

  1. #1

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Access Shared Buffers

    Hello

    I'm playing with ANT+ sensors, and now I'm wondering what's the best way to accomplish this scenario:

    - I have several lists, lets call them buffers, that will receive several values at different rates/time, then in another thread that at a specific interval get "atomic" access to the buffers, and remove all the data for managing, after that release the buffers to receive new data. I don't want to loose any data, when the thread it's getting the data.

    What's the best way to do this?

    SyncLock , Semaphores, other way?

    Thanks

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  2. #2
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    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.

  3. #3

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    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...

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  4. #4
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    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.
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  5. #5

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    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

    Rate People That Helped You
    Mark Thread Resolved When Resolved

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width