in reply to Re: Pre-caching large constants
in thread Pre-caching large constants
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 |