Click here to Skip to main content
16,007,885 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how to get info from stdio? Pin
Mike Nordell30-Jun-02 0:20
Mike Nordell30-Jun-02 0:20 
GeneralRe: how to get info from stdio? Pin
includeh1030-Jun-02 21:06
includeh1030-Jun-02 21:06 
Generalfriend function problem ... Pin
Hadi Rezaee28-Jun-02 16:33
Hadi Rezaee28-Jun-02 16:33 
GeneralRe: friend function problem ... Pin
moswal28-Jun-02 17:46
moswal28-Jun-02 17:46 
GeneralMemory Context Memory Leak Pin
moswal28-Jun-02 16:08
moswal28-Jun-02 16:08 
GeneralCircular Queue Pin
JohnnyG28-Jun-02 14:55
JohnnyG28-Jun-02 14:55 
GeneralRe: Circular Queue Pin
Ancient Dragon28-Jun-02 15:28
Ancient Dragon28-Jun-02 15:28 
GeneralRe: Circular Queue Pin
subtractive30-Jun-02 7:28
subtractive30-Jun-02 7:28 
The basic circular buffer is as you describe in point 5. Maintain two numbers, Read and Write which correspond to the read and write locations within the buffer. You can then use array notation rather than pointers which makes the arithmetic more intuitive.

Let's use recording audio as an example. The soundcard driver gives you regular buffers of data. Simply copy this into your circular buffer at the write position. To make wrapping arithmetic easy (and also ensuring only one memcpy is needed per iteration), make the size of your circular buffer a multiple of the size of the buffers the soundcard provides. For example, if the soundcard gives you 1024 sample buffers, make the circular buffer 16384 samples long.

Decide what rate you want to read data from the circular buffer e.g. in 8192 blocks. Then when you write to the circular buffer firstly update the write location and then check to see if the difference between read and write is >= 8192 (easy way to do this is to add the size of the circular buffer to each location and then take the difference). If it is, then signal your read thread to read the fresh data (and update your read pointer). This is easier than getting your read thread to continuosly poll thus leaving it more time to finish the formatting. Everytime you change the read or write values, make sure you use modulo arithmetic:

Write+=1024;
Write%=16384;

Read+=8192;
Read%=16384;

Hopefully, you shouldn't have problems with overrun since you're forcing a read when data is available. Experiment with buffer sizes to find the most efficient way. With audio, it's good to have small buffers since you get low latency, in your case it may not be necessary; bigger buffers put less strain on the CPU.

Hope this is useful.
GeneralRe: Circular Queue Pin
JohnnyG30-Jun-02 12:53
JohnnyG30-Jun-02 12:53 
GeneralOpaque Label Controls Pin
AndyO28-Jun-02 14:45
AndyO28-Jun-02 14:45 
GeneralWinCE Help Files Pin
Mel Stober28-Jun-02 12:27
Mel Stober28-Jun-02 12:27 
GeneralRe: WinCE Help Files Pin
Anders Molin29-Jun-02 3:03
professionalAnders Molin29-Jun-02 3:03 
GeneralMulti language Pin
orcun colak28-Jun-02 11:51
orcun colak28-Jun-02 11:51 
GeneralRe: Multi language Pin
Scott H. Settlemier29-Jun-02 6:20
Scott H. Settlemier29-Jun-02 6:20 
GeneralMessageBox problem - only flashes Pin
David Viggiano28-Jun-02 10:38
David Viggiano28-Jun-02 10:38 
GeneralRe: MessageBox problem - only flashes Pin
Jason Henderson28-Jun-02 16:24
Jason Henderson28-Jun-02 16:24 
GeneralHelp me>>>>>>>>>>>>>>>> Pin
Michael Liu28-Jun-02 8:36
Michael Liu28-Jun-02 8:36 
GeneralRe: Help me>>>>>>>>>>>>>>>> Pin
Mike Nordell28-Jun-02 8:46
Mike Nordell28-Jun-02 8:46 
GeneralRe: Help me>>>>>>>>>>>>>>>> Pin
Jason Henderson28-Jun-02 16:23
Jason Henderson28-Jun-02 16:23 
GeneralRe: Help me>>>>>>>>>>>>>>>> Pin
Christopher Lord28-Jun-02 20:45
Christopher Lord28-Jun-02 20:45 
GeneralProblem with Buttons in Child Windows Pin
AndyO28-Jun-02 7:34
AndyO28-Jun-02 7:34 
GeneralOnly one column in reportview listcontrol Pin
ns28-Jun-02 6:44
ns28-Jun-02 6:44 
GeneralRe: Only one column in reportview listcontrol Pin
Mike Nordell28-Jun-02 8:38
Mike Nordell28-Jun-02 8:38 
GeneralRe: Only one column in reportview listcontrol Pin
ns28-Jun-02 8:57
ns28-Jun-02 8:57 
GeneralRe: Only one column in reportview listcontrol Pin
Shog928-Jun-02 10:23
sitebuilderShog928-Jun-02 10:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.