in reply to Improving memory performance

Also, according to mod_perl Developer's Cookbook, you want to be careful with modules that automatically export symbols to your namespace, like POSIX:

# original code (from mod_perl book) use POSIX; setlocale(LC_ALL, 'en_US'); # now stop symbol exporting... (from mod_perl book) use POSIX(); # instead of use POSIX; POSIX::setlocal(&POSIX::LC_ALL, 'en_US');

According to the same book, doing "use POSIX" consumes about 140KB just for exporting those symbols. If you have many modules that uses such modules, eventually this will easily compound to a few megabytes...

Replies are listed 'Best First'.
Re: Re: Improving memory performance
by Sihal (Pilgrim) on Oct 04, 2002 at 09:58 UTC
    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 ?
      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 ?
        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?