Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^4: sub calls and memory use

by Anonymous Monk
on Nov 16, 2019 at 14:43 UTC ( [id://11108786]=note: print w/replies, xml ) Need Help??


in reply to Re^3: sub calls and memory use
in thread sub calls and memory use

You pass arguments in @_, as always.

So I was just using the wrong global variable! I can see now that pushing my arg into @_ before the &sub call prevents memory growth. Thank you Corion.

Replies are listed 'Best First'.
Re^5: sub calls and memory use
by LanX (Saint) on Nov 16, 2019 at 15:03 UTC
    In Perl you are generally better off translating tail calls to loops. They are way faster and easier to understand.

    You never explained your use case, but your example is easily translated with redo

    Concerning your memory growth, we'd need to know how you declared the "global var".

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      In Perl you are generally better off translating tail calls to loops.

      I replaced that recursive sub with a while loop and yeah, makes more sense, less code, and no memory bomb. ThanX

      Concerning your memory growth, we'd need to know how you declared the "global var".

      Sorry I was mistaken about that :-/

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 02:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found