double buffering technique

M

MPowell

Gents/Ladies, I'm doing (at least plan on ) lots of Reads and Writes
across a communication channel. I'm told that for the 'receive side'
it'd be prudent to implement a double buffering scheme to handle all
the asnychronous inputs.

Someone mentioned Herb Shutters book as frame of reference,
nonetheless, could someone provide sample code or - in effect an
outline of double buffering? I've perused the web but most references
are to 'GUI' applications which - quite frankly I'm not interested in.

If I understand double buffering, the idea is to create two buffers.
Lets say Buffer A and Buffer B. Now lets suppose data comes in to
Buffer A. The idea then is to swap Buffer A with Buffer B and as such
the next asnychronous input will write to Buffer B.

Thanks in advance.
 
T

Thomas Matthews

MPowell said:
Gents/Ladies, I'm doing (at least plan on ) lots of Reads and Writes
across a communication channel. I'm told that for the 'receive side'
it'd be prudent to implement a double buffering scheme to handle all
the asnychronous inputs.

Someone mentioned Herb Shutters book as frame of reference,
nonetheless, could someone provide sample code or - in effect an
outline of double buffering? I've perused the web but most references
are to 'GUI' applications which - quite frankly I'm not interested in.

If I understand double buffering, the idea is to create two buffers.
Lets say Buffer A and Buffer B. Now lets suppose data comes in to
Buffer A. The idea then is to swap Buffer A with Buffer B and as such
the next asnychronous input will write to Buffer B.

Thanks in advance.

You're very close.
The idea about using multiple buffers is that data is inserted into
one buffer while data is extracted from another. If the insertion
operation is faster than the extraction operation, multiple buffers
may be necessary.

Multiple buffers are used when the insertion and extraction operations
are performed asychronously, usually by two different processors.
For example, a communications processor (USB, USART, etc.) could be
told to dump to Buffer A. After Buffer A is full, it is told to
dump to buffer B. While it is dumping to buffer B, the processor
is extracting data from Buffer A and processing it.

See also:
1. Ring Buffers
2. Circular Queues
3. Deques

Further discussion is best handled in since this is a language independent issue.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
E

Eric Sosman

MPowell said:
Gents/Ladies, I'm doing (at least plan on ) lots of Reads and Writes
across a communication channel. I'm told that for the 'receive side'
it'd be prudent to implement a double buffering scheme to handle all
the asnychronous inputs.

Someone mentioned Herb Shutters book as frame of reference,
nonetheless, could someone provide sample code or - in effect an
outline of double buffering? I've perused the web but most references
are to 'GUI' applications which - quite frankly I'm not interested in.

If I understand double buffering, the idea is to create two buffers.
Lets say Buffer A and Buffer B. Now lets suppose data comes in to
Buffer A. The idea then is to swap Buffer A with Buffer B and as such
the next asnychronous input will write to Buffer B.

Your understanding seems correct, but Standard C can't
do what you want. Specifically, Standard C has no notion --
or very nearly no notion -- of asynchronous activities of
any kind at all, and lacks the mechanisms to coordinate them.
You'll need to resort to system-specific extensions that go
beyond the scope of the C language itself, and to learn about
those extensions you should consult newsgroups devoted to the
systems of interest.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top