Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re: Re: Re: writing looped programs

by count0 (Friar)
on Jan 29, 2002 at 08:52 UTC ( #142286=note: print w/ replies, xml ) Need Help??


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

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. =)


Comment on Re: Re: Re: Re: writing looped programs
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://142286]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2015-07-04 13:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls