in reply to Re: Improving memory performance
in thread Improving memory performance

I thought that if you used a module once ( in your main for example ) it would'nt increase the momory taken by subsequent calls in other modules also called by the main? Am I wrong ?

Replies are listed 'Best First'.
Re: Re: Re: Improving memory performance
by perrin (Chancellor) on Oct 04, 2002 at 13:33 UTC
    Remember, use also does an import. If the module exports any subs, they will take up a small amount of space in each namespace they are imported into. That's what he was referring to.
      So if I use a same module a multiple time in a script ( ie main calls module A, module A calls B and C but C also calls B and A ) the only memory I waste is by exporting the subs in each namespace ?
        That's correct. The module is only compiled once, but the imports happen in each namespace where the script is used, and they take up space. You can always simply avoid importing by calling a module with an empty import list, like this:
        use Foo::Bar ();
      Yes Perrin, I forgot that... so to minimize wasting of space maybe i should not always rely on exporting all the subs, but create groups and import them explicitely. ( like, i have an all purpose module that has grown quite big, with utility fincs, maybe I should import only whats needed in each script. Any ideas of how much memory it costs to import a func?
        Your goal should be to import nothing at all. Importing makes code more confusing and is kind of a crutch for doing perl4 style things in perl5. However, information on how much memory it costs is available here.