Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Threads with TBItmap, TJpegImage, TGraphics32

Status
Not open for further replies.

xor2

Programmer
Mar 24, 2005
22
Hello,

I have a procedure which performs some operation on jpg file (like transformations, etc).

I am;

- reading pixel from canvas
ACanvas.Pixels[X,Y];
- drawing on canvas
Bitmap.Canvas.Draw(0,0,jpg);
- assign bitmap from another source
Bitmap.Assign(LBitmapPomn);

The problem is that when i Run this procedure in a one thread everything is perfectly allright. I don't have memory leaks nor I have increased number of GDI objects and
the memory in the process manager varies from 50 to 100 mb and after this it returns to its default value.

The problem starts when i want to run this procedure in 4 threads. I have memory leaks. Memory inscreased to 1.7 gb, gdi +500 objects and so on..

I know only that Graphics32 component is thread-safe.
What about TBitmap, TJpegImage?
Which operation with this classes I should "Lock", should I lock?

Could the memory leak occur because of using these components?

How Can i fix my code?

Thanks for help in advance..





 
as you noticed, the VCL is not threadsafe. and yes you must lock the canvas before manipulating it (writing AND reading)

some guidelines:

canvas manipulations: main thread
calculations : you can use other threads, don't for get to synchronize with the main thread and between other calculation threads.

some more info:


/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Thank you for your post and the link which helped me understood how I could use Synchronize method with canvas manipulations.

By the way, Are you familiar with Graphics32?
Do you know if Graphics32's canvas is thread-safe?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top