PDA

View Full Version : Memory Problem with SIGNALS and SLOTS



^NyAw^
19th March 2007, 19:15
Hi,

I'm developing an image processing program that have to display the images from 4 cameras.

I have a QWidget that opens a window (using functions provided by the camera manufacturer).

I also have one Thread for each camera that is grabbing images and sending them to the main thread, when the main thread recives an image via SIGNAL/SLOT mechanism, itwill display the image.

The problem is that if I use the 4 cameras, the memory consumption is growing because the main thread is getting very much images per second. The memory conumption will grow to the top of the memory of the system, then it crash.

If I only use 2 cameras there is no problem.

I have tryied to increase the main thread priority but nothing.

I think that the main thread even loop is not able to destroy the images from the memory because it has not sufficient time.

Is there anyway to force the main thread to destroy an image after I displayed it?

Any one has any idea how to improve this?

Thanks,

wysota
19th March 2007, 20:39
Store images to be displayed in some kind of shared buffer protected by a mutex. If the buffer already contains an image, overwrite it as it's already obsolete, even if it hasn't been displayed yet. Let the main thread periodically check buffers from each data source and display images which are currently in buffers. This should reduce memory usage and improve responsibility as the main thread won't be displaying old images. Remember about protecting the buffers with mutexes!