FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   Applet Speed problems (image?)
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Applet Speed problems (image?)  (Read 776 times)
kevin

WWW
Applet Speed problems (image?)
« on: Sep 8th, 2003, 10:55am »

Hi,
 
Is there a significant speed decrese in applets? I built something last night which completely dies when viewed in a browser.
 
I'm loading an image so perhaps that's it, but I couldn't find any problem listed with that on the forums of the webpage? Did I miss something?
 
http://www.multiblah.com/pds/new/animated_m/
 
Thanks a lot,
 
- Kevin
 
toxi

WWW
Re: Applet Speed problems (image?)
« Reply #1 on: Sep 8th, 2003, 11:56am »

can i ask what your thinking process was leading to calling loadImage() from within the loop() and not the setup() method? this is an honest question and the reason i'm asking is that this somehow seems to pop up very often in the last 2 weeks. if you could elaborate on your thoughts behind this a bit further, that'd be very helpful... thanks!
« Last Edit: Sep 8th, 2003, 12:21pm by toxi »  

http://toxi.co.uk/
kevin

WWW
Re: Applet Speed problems (image?)
« Reply #2 on: Sep 8th, 2003, 12:43pm »

I think you'll find that's because I'm silly.
 
When I was building the thing, I was using the draw() function first. Then when I changed it to loop() I forgot about it entirely since it worked fine.
 
I wonder if that's the problem. I'll have to take a look at it again.
 
Incidentally, where's the best practice to call it? before setup() entirely?
 
toxi

WWW
Re: Applet Speed problems (image?)
« Reply #3 on: Sep 8th, 2003, 2:00pm »

oki...
 
i only find it slightly disturbing that quite a few people are doing that very same mistake. maybe this misplacement of loadImage() also has to do with the still widespread confusion of the exact purpose of the setup() function. to me this is admittedly slightly inexplicable as i consider everything to do with allocating resources, initalising important variables etc. as "setting up" tasks. but then again, you can have perfectly viable structure like this:
 
Code:
BImage img;
 
void setup() {
  img=loadImage("m.gif");
}

 
maybe it has to do with not being aware of the difference of declaring and initialising variables? in the above example the variable "img" is declared before, but only initialised once setup() is executed. whereas writing:
 
Code:
BImage img=loadImage("m.gif");

combines both steps into one. however as you're executing actual code, this has to be called from within a defined method, such as setup() or loop() etc. the reason why loop() would be wrong though is, that every frame you're reloading the image from your server, which generally is much sloooower than loading it from your harddrive during authoring.
 
again, excuse me asking strange questions, but why would you want to do that now *before* setup() and not within it? i think if we have answers to these questions, maybe we can come up with solutions (either in the reference or otherwise) to avoid such misconstructs in future.
 
thanks!
 

http://toxi.co.uk/
kevin

WWW
Re: Applet Speed problems (image?)
« Reply #4 on: Sep 8th, 2003, 3:29pm »

Well, I'd say most people make the mistake like me.
 
It's often like that when you're learning a new environment, where you learn how to do things before you learn how to do them right. It's the problem with self teaching I find.
 
Still though, that's very much for asking that question, after you did, I went and moved everything outside of loop() and now it works fine in both the browser.
 
FYI you can see how it's supposed to work now:
 
http://www.multiblah.com/pds/new/animated_m/
 
Hopefully that's a better way of doing.
 
Thanks for the help.
« Last Edit: Sep 8th, 2003, 3:33pm by kevin »  
benelek

35160983516098 WWW Email
Re: Applet Speed problems (image?)
« Reply #5 on: Sep 9th, 2003, 7:03am »

i've always thought of setup() as similar to the <head> part of an html page - the place where you want to put code that's run before anything else on the page.
 
as a matter of interest, do p5 applets put images in cache - or do they get reloaded every time loadImage() is called, even if it's the same image? for instance, does the following load an image twice?
 
Code:

BImage one = loadImage("bla.jpg");
BImage another = loadImage("bla.jpg");
 
 
toxi

WWW
Re: Applet Speed problems (image?)
« Reply #6 on: Sep 9th, 2003, 12:12pm »

i think the caching depends on your java plugin prefs (if you use the plugin at all) - by default caching in java is disabled, so yes... every loadImage() will result in an HTTP request with all the delay this involves. if reading locally from HD, it's very likely that the image is cached in the disk buffers in RAM most of the time, hence the delay of calling loadImage() repeatedly is often unnoticable...
 

http://toxi.co.uk/
Pages: 1 

« Previous topic | Next topic »