-
April 21st, 2012, 02:09 PM
#1
[RESOLVED] Writing image data to disk in parallel?
So I actually posted my question to StackOverflow, but did not really get an answer.
Basically, I want to write an image to disk in parallel with an algorithm that is processing that same image. The code is really simple:
Code:
string ProcessImage(System::Drawing::Bitmap ^bmp, System::String^ targetFile)
{
bmp->Save(targetFile);
System::Drawing::Bitmap^ bmp8 = BitmapConvertPixelFormat(bmp, 8); //<-- a function I wrote which converts the 32bpp I am passed into an 8bpp one
string results = Analyze(bmp8); //<--- takes a good bit of time
return results;
}
What would be the fastest way to do this? Please let me know of any libraries you recommend with a code sample. I would prefer one that is within .NET or native C++ just to avoid having to link into many different libraries.
Thanks in advance!
-
April 21st, 2012, 03:48 PM
#2
Re: Writing image data to disk in parallel?
How much time do you expect to save by doing this? The most you could save would be the smaller of (Time to save file) and (Time to process bitmap). In your case (Time to save file) will be much less than (Time to process bitmap), so the user wouldn't really notice any improvement anyway.
Could you put some code in to time these two parts so you know how much improvement you could make?
-
April 21st, 2012, 04:12 PM
#3
Re: Writing image data to disk in parallel?
First of all, why did you post this in the Non Visual C++ section? Since you are using C++/CLI, you should have posted it here.
Originally Posted by Amil
Basically, I want to write an image to disk in parallel with an algorithm that is processing that same image. The code is really simple:
Code:
string ProcessImage(System::Drawing::Bitmap ^bmp, System::String^ targetFile)
{
bmp->Save(targetFile);
System::Drawing::Bitmap^ bmp8 = BitmapConvertPixelFormat(bmp, 8); //<-- a function I wrote which converts the 32bpp I am passed into an 8bpp one
string results = Analyze(bmp8); //<--- takes a good bit of time
return results;
}
Since both the saving and processing only reads the bitmap bmp, you can just send the saving off to a different thread. Since you are already using .Net, I suggest using ThreadPool::QueueUserWorkItem.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
April 21st, 2012, 04:16 PM
#4
Re: Writing image data to disk in parallel?
Uh... am I missing something? That's not C++. What do you think the ^ operator is?
-
April 21st, 2012, 06:29 PM
#5
Re: Writing image data to disk in parallel?
Thanks for the responses. I guess I'll first time the save and processing of the bitmap. I'll also look into using ThreadPool::QueueUserWorkItem like D_Drmmr suggested.
Also, if a moderator could move this into the C++/CLI section, please do so. I wasn't sure where to post this at first as I thought the concept of C++ multi-threading was general enough to go in either section.
EDIT: I got it working with ThreadPool::QueueUserWorkItem! Preventing race conditions was a bit tricky, but I found this interface really easy-to-use for threading.
Last edited by Amil; April 21st, 2012 at 11:15 PM.
Tags for this Thread
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
|