http://qs321.pair.com?node_id=354955

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.

Gorby

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.

    --
    TTTATCGGTCGTTATATAGATGTTTGCA

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?)