module load question

C

Chuck Mattern

I've been asked to take a look at some very badly written Perl in use on a
number of our servers. One of the issues is that as it runs it consumes more
and more memory. I've only had a chance to do a cursory read of the code but
one thing that intrigued me was a directive to use a module that was inside of
a loop, with each iteration the module was called again. Is it possible that
this is part of the memory consumption? Would each reference load a new copy
of the same module in another segment of memory leaving the previous copies in
memory as well or would the new one be ignored or would each new call overwrite
the previous copy?

Looking forward to the thoughts of group,
Chuck
 
I

Iain Chalmers

Chuck Mattern said:
I've been asked to take a look at some very badly written Perl in use on a
number of our servers. One of the issues is that as it runs it consumes more
and more memory. I've only had a chance to do a cursory read of the code but
one thing that intrigued me was a directive to use a module that was inside
of
a loop, with each iteration the module was called again. Is it possible that
this is part of the memory consumption? Would each reference load a new copy
of the same module in another segment of memory leaving the previous copies
in
memory as well or would the new one be ignored or would each new call
overwrite
the previous copy?

Neither. Perl is smarther than that.

perldoc -f use

says (amongst other things:
It is exactly equivalent to

BEGIN { require Module; import Module LIST; }

and:

The `BEGIN' forces the `require' and `import' to
happen at compile time. The `require' makes sure
the module is loaded into memory if it hasn't been
yet.


if its already loaded, "use"ing it again does nothing... You'll need to
look somewhere else for your problem...

cheers,

big
 
T

Tore Aursand

I've only had a chance to do a cursory read of the code but one thing
that intrigued me was a directive to use a module that was inside of a
loop, with each iteration the module was called again. Is it possible
that this is part of the memory consumption?

No;

perldoc -f use

See for yourself; Move the 'use' parts out of the loops and let the
program run for a while, and you should see that it still eats up memory.
Alas, your problem seems to be elsewhere.
 
C

Chuck Mattern

See for yourself; Move the 'use' parts out of the loops and let the
program run for a while, and you should see that it still eats up memory.
Alas, your problem seems to be elsewhere.

Many thanks, in my heart I knew that would be too easy...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top