views:

328

answers:

3

Hi,

I am trying to load thousands of images using NSThread but the performance is quite slow.

What would be the best practice to use NSThread to download thousands of images?

Thanks,
Jim.

+1  A: 

If you are downloading images over http I recommend using the ASIHTTPRequest framwork. It can easily download html, images and other stuff asynchronous.

But, be careful not to download to many things at the same time. I have read somewhere that 10 http connections at the same time should be a good amount. (Somewhere was the AppSales-Mobile project ReviewUpdater.h value set by jonkean in his commit)

epatel
+1  A: 

NSThread isn't the problem. It sounds like you might be simply overwhelming the iPhone hardware. Remember, a mobile platform has only a fraction of power of even the slowest laptop.

Look at how the photo app has to blur-fade in images at times. Sometimes, it has to do that with thumbnails as well. It can take up to 10-20 seconds to display a graphics intensive web page.

It sounds like you need to rethink your design. Unless you're loading microscopically small images, your simply not going to load "thousands" of them in a timely manner on iPhone hardware. You need to load as you display. Logically chop the images up into groups and then have the user navigate to the group they want and then load only that small group.

TechZen
Yeah That's true NSThread wasn't the problem. I once again thought on design and now with new design application looks good. Thanks a lot.
Jim
+2  A: 

Also consider to use the NSOperationQueue to coordinate those downloads. Using the NSOperationQueue and NSOperation classes you can schedule a thousand downloads but make sure that only a certain amount of downloads happen concurrently.

To score bonus points, use the Reachability API to see if the user is on 3G or Wifi and set the number of concurrent downloads based on that.

St3fan