Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Re: Pre-caching large constants

by hossman (Prior)
on Feb 08, 2002 at 22:21 UTC ( #144263=note: print w/replies, xml ) Need Help??

in reply to Re: Pre-caching large constants
in thread Pre-caching large constants

I don't think SelfLoader or AutoLoader are really what he wants here. They are designed for situations in which the compilation of code is very expensive, and you don't want to bother unless the code is needed.

In this case, it sounds like the code to populate the constants is relatively simple, and won't take long to compile, it just takes a while to run.

This screams accessor to me.

Instead of making these constants part of your 'public' API, make them internal, and write an accessor for them that initializes them the first time it calls, and returns them everytime after that:

package mypackage; my $sqrt_2 = undef; # not visible outside of mypackage sub get_sqrt_2 { unless (defined $sqrt_2) { # do a bunch of work to set $sqrt_2 } return $sprt_2; }

Replies are listed 'Best First'.
Re: Re: Re: Pre-caching large constants
by lestrrat (Deacon) on Feb 08, 2002 at 22:34 UTC

    Oh I get it. Right, it's the computation in itself that's the problem. Yep, then probably not SelfLoader or AutoLoader

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://144263]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2023-10-04 06:28 GMT
Find Nodes?
    Voting Booth?

    No recent polls found