Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Re: writing looped programs

by count0 (Friar)
on Jan 28, 2002 at 23:46 UTC ( #142169=note: print w/replies, xml ) Need Help??

in reply to Re: writing looped programs
in thread writing looped programs

I'm thinking it'll save memory that way - sleep before the variables are set, rather than after they're used.

I don't believe this will prove beneficial. Perl implements garbage collection, and in most cases will not free() that memory anyhow. So once the variable goes out of scope, its memory is flagged to be reused, iirc.

Replies are listed 'Best First'.
Re: Re: Re: writing looped programs
by mrbbking (Hermit) on Jan 29, 2002 at 01:34 UTC
    So once the variable goes out of scope, its memory is flagged to be reused, iirc.
    Yeah - that's what I was thinking.

    If the sleep is at the top of the loop, before any my variables have been declared, then the variables can't be taking up any memory.

    If the sleep is at the end of the loop, then all my variables declared in the loop are still in scope, and therefore must continue to exist.


      But if we're talking about a loop, this memory conservation only exists in the first iteration of it.
      while (1) { # during the first iteration, no variables have been # declared yet. # However, if we're in the 2nd, 3rd, etc loop.. # that 3ish KB of memory allocated for $variable # still belong to Perl, and are most likely not yet # free()'ed sleep 10; # Create roughly 3 KB { my $variable = 'foo' x 1024; } }

      So you see... we conserve memory for an extra 10 seconds (the first 10 seconds of this code's execution)... but that's it. After that, Perl holds on to that memory created for $variable... even when $variable goes out of scope. So the position of the sleep really makes no real difference.

      Anyway, these sorts of attempts at micro-optimizations usually prove to be futile, as Perl does a great job of it on its own. =)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://142169]
[RonW]: Why not ytdl >data then ffmpeg <data ?
[RonW]: (I use Windows as little as possible)
[LanX]: RonW: yes I think something like inline::Rperl would be great, but Will is AFAIK not interested to go that way
[james28909]: well now i am using a for /f delims= %i IN(yt-dl) do set var=%i & ffmpeg -i "%var%" -a:c mp3 output.mp3 & set var=
[james28909]: just to get around not being able to do yt-dl | ffmpeg
[james28909]: learning is fun ISNT IT?!?!!??
[RonW]: that seems very weird to me
choroba submitted 2 talks to (YA|T)PC::EU
[RonW]: Choroba: I hope they get accepted

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2017-05-22 21:21 GMT
Find Nodes?
    Voting Booth?