We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Spreading a sketches workload
Page Index Toggle Pages: 1
Spreading a sketches workload (Read 976 times)
Spreading a sketches workload
Feb 2nd, 2010, 7:32am
 
Is there a way to tell Processing to 'take it easy' when executing tasks?

I have a sketch, which involves a lot of 'loadImage' calls. It's working fine, but slows down when I increase the number of images that Im asking it to draw. The images need only be loaded once, & I don't really mind having to wait a little while for my sketch to completely load and start running, but the number of images I would like to load is possibly going to be too much for Processing/my computer to handle.

Is there a way to either tell processing to load everything nice & slowly to avoid crashing? or is it possible to launch the applet from the command line through Terminal on OS X and spread the load over a number of computers on a network?
Re: Spreading a sketches workload
Reply #1 - Feb 2nd, 2010, 1:40pm
 
If you want to load all the images at the start and keep them "in memory" until the end, there is no benefit in loading "slowly" - either they will fit or they will not.

If you have a large number of images that are displayed once (or only for a short duration) before moving on to other images, perhaps you need to come up with some loading strategy; if you're trying to run a continuous image sequence, you may find that your system isn't fast enough to load them in "real time"; that is, there may always be some point (on your system, with the images you're trying to load, etc) at which you suffer delays.

But, first things first. You're worried about something that *might* happen. Just try it, and if the bad thing you're worried about doesn't happen, don't worry about it.  Wink
Re: Spreading a sketches workload
Reply #2 - Feb 9th, 2010, 5:21am
 
If you want to load all the images at the start of the program you can call the loadImage constructor in setup.  this will only run once, and will always store the image in the specified variable unless a new constructor is called on it.

I am assuming you are using the PImage class:

       PImage  img;

       void setup ()  {
         size(whatever, whatever);
         img = loadImage("File Location");
       }

I myself have been experimenting with loading images in an embedded sketch to reduce the load on the sketch displaying the images.  I will post again if I have any success.
Re: Spreading a sketches workload
Reply #3 - Feb 9th, 2010, 6:27am
 
Yes, unfortunately in my current situation not all of the images I need are available at the start of the sketch (they're coming from a feed from somewhere outside my sketch).
This has clarified matters a little though, so if Processing needs only adequate memory, I might just have to be really careful about how many images to keep at one time.

Just to check, does setting a PImage array value to null remove the image free up that bit of memory once more?
Re: Spreading a sketches workload
Reply #4 - Feb 9th, 2010, 6:30am
 
yes, but not immediately. it marks it so the garbage collector can delete it. but the garbage collector only runs from time to time.

might be better to reuse the same pimages, loading the new pictures into the old slots. might be.
Re: Spreading a sketches workload
Reply #5 - Feb 9th, 2010, 6:56am
 
Ok no worries I'll give it a go, maybe it'll help maybe not. Or maybe I just need to get my hands on a bit of a beefier computer! Cheers for that anyway:)
Re: Spreading a sketches workload
Reply #6 - Feb 9th, 2010, 9:47pm
 
loadImage() waits until the image is loaded, which is a problem if you want to update your display while it is loading.

requestImage() loads the image in a separate thread, and sets the image's width when the loading is complete (<0 for error, >0 with proper image width for success).

I posted some code to display images from several web image feeds on OpenProcessing.org (it is too long to post here).

Link: Live feed selector

I've tried to take into account things like how often to request a new image, which you will probably want to be able to adjust depending on the source.

-spxl

PS: Please disregard the Arduino code in that sketch. I don't have an Arduino device to test with.
Page Index Toggle Pages: 1