in reply to Re: endless loop problems
in thread endless loop problems

Then again, maybe OPs code was working. Maybe he thought it was endless due not getting any prints back and because every image has to be loaded into memory for it to be sized. From ImageFap, that's one long wait because they are super slow.

Code might not be pretty but other than the loop variable not increasing, I think it should work the way it is. I'd try to turn on the buffer var and see what happens.

UPDATE: would it not be better for the server in terms of CPU and memory if the images were downloaded into a temp directory and sized locally rather than read from memory?

Replies are listed 'Best First'.
Re^3: endless loop problems
by ikegami (Patriarch) on Jun 28, 2006 at 16:28 UTC

    I don't understand what you are trying to say in the first two paragraphs. (Yes, the debug statements would have worked with $| = 1. Yes, it would have worked by replacing $pics_found with @found_images. Just like I said in my post.)

    If your point is that you're taking exception to me cleaning up the code, keep in mind that good code is readable and maintainable code. The excess of redundancy and the poor choice of variable names in the original code affected both readability and maintainability.

    would it not be better for the server in terms of CPU and memory if the images were downloaded into a temp directory and sized locally rather than read from memory?

    The CPU usage would be (slightly) higher, since we'd have extra code to write to the disk and read from the disk.

    Yes, the memory usage could be smaller (depending on how we write to and read from the disk) by something less than the size of one image.

    And of course, it would be slower because we'd have to do all the work we currenlty do, plus more.

      This might be getting a little on the OT side but how much memory is used up at a time in this situation? Does the memory clear after each image? Does it pile itself up?

      I'm not so much into the technical side of things, but I'd have to think that storing an image locally might take a little longer but it would clear up a lot of unecessary memory and it'd be faster to process the image sizes if they were locally stored. So when it comes to the memory usage, if storing the files, wouldn't it only be a problem for a short while instead of the duration of the entire loop above?

      I could be speaking nonsense as I have no real clue how this stuff really works.

        This might be getting a little on the OT side but how much memory is used up at a time in this situation?

        length($gal) + length($image) + size of list of urls + overhead

        It could be changed to
        max( length($gal), length($image) ) + size of list of urls + overhead
        but it's probably not worth it.

        Does the memory clear after each image?

        Yes. Variables $gal and $img get freed (to Perl, not to the OS) at the end of their respective enclosing blocks, since they are lexically scoped (my) variables. I could modify the code (by adding a set of curlies) to free $gal sooner, but it's not worth it.

        Only one gallery is memory at a time.
        Only one image is memory at a time.

        I'd have to think [...] it'd be faster to process the image sizes if they were locally stored.

        No. You'd have to extra steps of storing them locally and reading them back in to memory (if only a bit at a time). That's a lot of disk IO you didn't used to have.