-
September 13th, 2015, 04:32 AM
#1
Real Time reading and drawing
Hello there,
I am looking for the best Way/Strategy to "Continuously read data from the HW in real-time and draw some GUI-diagram in Parallel". Performance would be a big matter here since the graph has to be drawn in real-time.
Its just coming to my mind about 1) creating 1 worker-thread for reading process, and 2) another for GUI drawing.
But I am looking for perfection and suggestions here.
1) Is there any specific Design-Pattern that would fit this?. If so, please suggest.
2) Whats the best way(container) to read data by the worker-thread and keep it for the GUI-thread to process. FIFO? or some other class?
Thanks in advance for your suggestion and advice.
-
September 13th, 2015, 02:25 PM
#2
Re: Real Time reading and drawing
Is there anything else that needs to be done to the data, or can the GUI thread discard the data after processing it?
gg
-
September 13th, 2015, 09:51 PM
#3
Re: Real Time reading and drawing
Thanks for the reply.
Yes, preferably the data need to be saved for some other purpose later, even after the GUI is been drawn.
-
September 14th, 2015, 07:24 AM
#4
Re: Real Time reading and drawing
1) windows is not a real time system. You have to allow for frames to get dropped, and this need becomes highher the higher the framerate you need to go. This shouldn't be a problem because if you're updating faster than say 5 frames per second, nobody will notice an intermediate flash and 'recognize' it. If it's about smooth motion, then anything above 25-30frames is enough to fool the human eye into thinking it's continuous.
2) simple solution is you have 3 memory DC's with an associated bitmap.
You need 3 to:
- A one for the image that is currently pending for display or in the process of being displayed
- B one for the data thread to create a new image in
- C one free for the data thread to swap over if data is arriving faster than the display can handle.
The data thread fetches data, puts it on the bitmap, swaps B with C (thread safe), informs the main thread an image is ready
GUI thread waits for an update notification, swaps A with B (thread safe), paints A.
if the data thread gets so much data that it can't process it to a bitmap fast enough, you need an extra layer, and an extra thread. with databuffers swapping between the data reader thread, and the bitmap calculation thread.
-
September 14th, 2015, 09:25 AM
#5
Re: Real Time reading and drawing
Here is an example of a simple data structure for sending data from one thread to another:
http://cboard.cprogramming.com/windo...tml#post966940
Notice the queue_MT::enqueue(It first, It last) and queue_MT:equeue_all() methods. By adding to the queue in batches, and consuming the entire queue at once, lock contention can be significantly reduced. The GUI thread could then pipeline the data to a third thread for writing to a file. Or use overlapped IO to write the data to file and render it at the same time in the GUI thread.
gg
-
September 21st, 2015, 10:21 PM
#6
Re: Real Time reading and drawing
Idea isn't bad. Great thinking as usual. carry on!
-
September 21st, 2015, 10:23 PM
#7
Re: Real Time reading and drawing
Originally Posted by FrankStar
Thanks for the reply.
Yes, preferably the data need to be saved for some other purpose later, even after the GUI is been drawn.
Right! Data should be save for future purpose.
-
September 6th, 2016, 10:18 AM
#8
Re: Real Time reading and drawing
any idea for body structure sketch.
-
September 6th, 2016, 12:14 PM
#9
Re: Real Time reading and drawing
Originally Posted by JamesHoward
any idea for body structure sketch.
...and this relates to the OP how?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 7th, 2016, 12:59 AM
#10
Re: Real Time reading and drawing
Its good article shoews all detail for multithreading.
-
October 28th, 2016, 07:46 AM
#11
Re: Real Time reading and drawing
I'm not aware of another method that tells you that you can have exclusive ownership of a file. Trying again a couple times a second won't hurt.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|