[EMAIL PROTECTED] wrote:
> Hello,
> 
> I have a module,which loads large data into memory.
> 
> my $data = Mymodule->new;
> 
> this will take some ms to be finished.

And consume large amounts of RAM too I would imagine.

> So I think I can create this object at startup time,and share the $data 
> acrosss all apache child processes.
> 
> Is it possible?How can I do it?

Yes, possible. Just assign the data to a named global at startup time.

ie.

<httpd.conf>
PelrModule My::Module
</httpd.conf>

<My/Module.pm>
package My::Module;
use Mymodule;
our $data = Mymodule->new;
</My/Module.pm>

Than anywhere you want, just refer to $My::Module::data

Generally, when doing something like that, you want to make 100% certain
that your data is read-only, otherwise, any changes to it won't be reflected
for every child process, and tons of memory will get suddently unshared.

To avoid that, checkout the various ways you can make something truly
read-only. (Hash::Util::lock_hash, Readonly.pm, etc)

------------------------------------------------------------------------
Philippe M. Chiasson     GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/       m/gozer\@(apache|cpan|ectoplasm)\.org/

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to