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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I've got a module that I'm working on where I am pre-caching a number of very large constants, created with Math::BigFloat. My problem is this: I've got 10 or 12 of these very large constants, but for the most part, only one or two of them are going to used at any given time. That being the case, I don't want to automatically dump all of them into memory, only the ones that a user asks for. For example, I've got the square root of 2 and the square root of 5 ($_sqrt2_ and $_sqrt5_, respectively) as two of these constants. Let's say I only need $_sqrt2_. What would be the best method for creating these via Math::BigFloat "on demand?" My first thought was to make a CONSTANT() routine where the user would pass the name of the constant they want and have it created at that time. It seems to me, though, that there should be a better way. I did some digging through the search here, but didn't find anything (perhaps I was searching for the wrong thing?). Any suggestions?

Many thanks.
___________________
Kurt

UPDATE (11-Feb-2002 10:21:38 AM): By way of further clarification, the problem isn't that I'm concerned about the calculation time of these constants. I'm pre-calculating them and I'm subsequently hard-coding them as Math::BigFloat objects. My concern is a memory issue since some of these constants are very, very large. I suppose a few extra kb of memory probably isn't going to make much of a difference, but it is The Principle of The Thing. My original plan was to use an accessor method similar to that described by hossman to avoid dumping all of these constants into memory if only one or two (or possibly even none) are going to be used in a given script. Forgive me for showing my ignorance here, but does the Tie::Scalar method that japhy used accomplish this? I've never used Tie::Scalar before, so I'm a little in the dark, even after reading the docs.

In reply to Pre-caching large constants by sifukurt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-25 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found