Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

RAM Question

by Gorby (Monk)
on May 20, 2004 at 14:22 UTC ( #354955=perlquestion: print w/replies, xml ) Need Help??

Gorby has asked for the wisdom of the Perl Monks concerning the following question:

Hello Wise Monks.

Does merely declaring variables with "my" consume RAM, or does a perl program take up RAM only when a value is assigned to a previously declared variable?

Also, do unused variables consume RAM?

Thanks in advance.


Replies are listed 'Best First'.
Re: RAM Question
by Ryszard (Priest) on May 20, 2004 at 14:46 UTC
    I'm not quite sure what you _really_ mean here, but the answer to both your questions is yes.

    Perl itself runs in ram, and each bit of extra program you write consumes a little bit of RAM.

    If you declare something, perl will allocate some space for it. You can reduce the RAM used by your vars by undef'ing them when they're not needed, but if the variable exists, then there will be a little bit of ram used.

    Perhaps i'm misunderstanding the question, or perhaps someone else can explain it a better than i.

Re: RAM Question
by TomDLux (Vicar) on May 20, 2004 at 16:25 UTC

    When you declare a variable, it's like addressing an envelope. (Though I wonder if describing something in terms of envelopes is informative, in these days of email .... Like the other day, I explained soemthing to some younger people in terms of children learning to tie their shoelaces, and found out they grew up with velcro shoes.) When you assign a value, you fill the envelope ... that may or may not require extra space.

    Check out PerlGuts Illustrated if you want to know more.

    Personally, since I've managed to avoid needing to do anything with the internals, I have found that small doses of guts are best; learning is a cumulative proceess. Another way of looking at it, each time I investigate, I become convinced I don't need to know more.


Re: RAM Question
by chromatic (Archbishop) on May 20, 2004 at 16:31 UTC

    I'm going to show you photographs of people and tell you their names. I'd like you to remember both the names and the faces. Their names are Sally, Robert, Benjamin, Arvin, and Marcus.

    Though I haven't shown you the photographs yet, please keep the names in mind until I tell you you can forget them.

    (Variables are names. Does that help?)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://354955]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2022-10-03 07:35 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (13 votes). Check out past polls.