[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Data passing

Posted on 2011-03-22
Medium Priority
Last Modified: 2012-05-11
I'm working on a DLL which will serve as the back end or engine for an arbitrary Win32 GUI front end to connect to. My back end should have no graphical code, of course. What I'm making is an interface for a camera-like device. This device has an SDK I'm using which utilizes CALLBACKs. Through several of these callbacks, which run in their own thread, I receive an image (as an object) from the camera device. I need an efficient way to forward this image to the Win32 GUI developer without exposing him to the SDK's callback functions. This image must be immediately forwarded because the Win32 Developer may want to display it the moment it is received, as these images are continually streaming from the device. (Ultimately, if you were to display the images as they came from the device, what you would get is a video in real-time of the images being captured by the device).

I'm not asking anyone here to solve my problem, but, as an entry level coder, I would like input as to what my options are and what the pros and cons are to each solution. I am concerned with speed.

I'm using MS VS 2008 on Windows XP to write the DLL in C++. The SDK is a DLL and static LIB written in C using an unknown compiler. I don't know how relevant that info is, but, there it is.
Question by:Josiah14
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
LVL 31

Expert Comment

ID: 35196661
Question to ask is whether you are simply sampling what happens on the camera, the point at which you say "data please" is effectively like a shutter release.  

I would start by dumping the output to files to see if that works.  If it does, how quickly can files be constructed?  Is that fast enough?  If so, your GUI Developer could just be told that the sequence of files is held in the image dump directory, the file names are in sequential order.  Last thing you want is for the GUI app to hold the data requester from firing, which would result in lost data.
LVL 35

Accepted Solution

sarabande earned 1800 total points
ID: 35197646
(1) you adopt the callback technique

the gui makes a request by calling a function in your dll and passes a callback function pointer. when you got the image for the request you call the callback passing the image with that call.

advantage: known technique, fast, allows direct pointer access
disadvantage: passes responsibility to gui. callback runs asynchronously in own thread-context,

(2) you write to shared memory and notify the gui when done

the gui makes a request by calling a function in your dll and passes a handle to a memory mapped file (shared memory) where you could write (copy) the image to. after write you notify success by posting a windows message to the gui.

advantage: fast and safe exchange. you also could provide the handle for the shared memory yourself as return to the request.

disadvantage: needs additional call for clearing the memory. uses additional system resources. can give additional sync problems when updating the image continuously.



Author Comment

ID: 35199095
Perhaps I should clarify, the device is a camera, but it is continually taking pictures.  Part of the objective is to allow the GUI to catch the streaming images from the device to make a sort-of 2D animation of what the camera "sees" in real-time.  This is the real difficulty at the moment, for taking the image from the camera and throwing it out to the GUI in an object is as simple as a regular method call, but I need to be able to give the GUI a way of knowing when the image is available so every time the camera produces the image, the GUI has the option to display it.  Outputting the image to the file system will not work as it will certainly be too slow.

I had considered using callbacks, but had not considered writing to shared memory.  Since the GUI will have a WinProc anyway, this could be a good method.  For what we want to do, the user has to explicitly make a call for memory cleanup already, so I could just throw that in with the device object cleanup.  I dunno if actually writing the image data to a file in shared memory would be too much overhead, though...  Something for me to consider.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 31

Assisted Solution

moorhouselondon earned 200 total points
ID: 35202832
Another thing to consider is to use delta techniques.  If the camera is in a fixed position then the first sample will be of all pixels.  Subsequent calls can be just of the changes that have occurred since the last sample.  this will substantially cut down data traffic and is a well-known technique used in security monitoring.
LVL 35

Assisted Solution

sarabande earned 1800 total points
ID: 35205385
the overhead for shared memory can be neglected if you use a sufficient large piece of memory where you could store more than one picture in a kind of ring buffer. that would decrease the amount of needed synchronisation to the overflow case where a camera has produced more pictures not yet displayed than the memory could take.


Author Closing Comment

ID: 35207095
This is great.  There's some applicable suggestions here that I never would have thought of.

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

cPanel is a Unix based web hosting control panel that provides a graphical interface and automation tools designed to simplify the process of hosting a web site. cPanel utilizes a 3 tier structure that provides functionality for administrators, rese…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question