Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

quick question on modules

by perlaintdead (Scribe)
on Feb 01, 2013 at 09:12 UTC ( #1016481=perlquestion: print w/ replies, xml ) Need Help??
perlaintdead has asked for the wisdom of the Perl Monks concerning the following question:

if you load a module like: use something::or::other qw(funt); will it use less memory than just: use something::or::other;

Comment on quick question on modules
Re: quick question on modules
by LanX (Canon) on Feb 01, 2013 at 09:38 UTC
    Normally no!

    Use means that a module-function import() is called at BEGIN-time.

    Normally this function is inherited by Exporter module and does only an aliasing of imported functions.

    And aliasing costs only some bytes, not enough to be discussed.

    But a module author can chose to define his own import and do whatever he wants... so no general answer here.

    Cheers Rolf

      A great counterexample is POSIX:

      Q:\>perl -MPOSIX -wle "print for grep {$_ =~ /$$/} `tasklist`" perl.exe 5508 Console 0 3.936 +K Q:\>perl -MPOSIX=strftime -wle "print for grep {$_ =~ /$$/} `tasklist` +" perl.exe 4904 Console 0 3.672 +K

      POSIX.pm exports all its functions and constants by default, which costs 300K memory, while importing just the few needed functions reduces the amount of memory spent.

      tl; dr - just like you said, no general answer here.

Re: quick question on modules
by vinoth.ree (Parson) on Feb 01, 2013 at 09:43 UTC

    If you use use something::or::other qw(funt) this method, it will export only funt symbol into the caller namespace.

    If you use use something::or::other method, it will export list of symbols (subroutines and variables) of the module to be exported into the caller namespace from @EXPORT array defined in something::or::other

      The question was "will it use less memory" not "what is the difference between ..."

        The question was "will it use less memory" not "what is the difference between ..."

        And then?

Re: quick question on modules
by perlaintdead (Scribe) on Feb 01, 2013 at 10:03 UTC

    /\ thanks to all above

Re: quick question on modules
by Anonymous Monk on Feb 01, 2013 at 13:17 UTC
    I suspect that it very often comes down to how many things, that are not already used, are brought in by the module being used.
Re: quick question on modules
by dsheroh (Parson) on Feb 02, 2013 at 09:07 UTC
    An important point alluded to, but never explicitly stated, by the earlier answers: The only difference is in which symbols are aliased into the useing module. All of something::or::other will be compiled and kept in memory regardless of whether you only import funt or import all available symbols1. The memory used to load the module's code will dwarf the memory used to alias the exported symbols into the user's namespace, so it's not going to be a significant difference.

    1 If the used module is built around Autoloader/AutoSplit/SelfLoader, this doesn't hold, as they allow the module to only load and compile subs on-demand instead of compiling the whole thing at program start-up. In my experience, though, this isn't done all that often, so it's probably safe to assume that any random module will be loaded in full if used.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-12-21 03:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (102 votes), past polls