in reply to Re^3: Techniques On Saving Memory
in thread Techniques On Saving Memory

Actually, I like yours best. A few other things that would improve it (for my envisage purposes) are:

  • If it also returned the package name into which the reference was blessed, if it was blessed, in a list context.
  • If it had a deref() function that (optionally?) incremented the ref count.
  • If it provided a safe method of checking the unsmashed reference was still valid.
  • Had a function that would detect and return the type of the unsmashed reference--SCALAR/ARRAY/HASH etc, but also (if it is possible?), the the type of magic to which it is bound. Ie. Classname, or REGEX (I forgot how these get created?) etc.

    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.
  • Replies are listed 'Best First'.
    Re^5: Techniques On Saving Memory
    by japhy (Canon) on Mar 10, 2005 at 15:39 UTC
      • I can see the "is it blessed" functionality being useful.
      • I'm not sure why you need to increment the ref count. Could you explain the reason?
      • I'll see how I can figure out whether there is a reference at the given memory location.
      • Determining the reference type and magic type shouldn't be too hard.
      _____________________________________________________
      Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
      How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
        I'm not sure why you need to increment the ref count. Could you explain the reason?

        See the discussion in this thread at Re^6: Techniques On Saving Memory. Basically, if you take a smashed reference, perl doesn't know you have it, so by the time you get to unsmash it, the thing you took a reference too could have been GC'd. If the refcount was (optionally) increased when a smashed refence was taken, and decremented when it was unsmashed, it would appear like an ordinary reference had been taken and GCing would be delayed.

        I still have doubts about how this would interact with other things, especially threads and shared vars, but if all that functionality was wrapped in a single place, it might at least allow the idea to be tested.

        It's already possible to do all of that using bist a pieces from half a dozen existing modules, but it would be useful to get it all from one.


        Examine what is said, not who speaks.
        Silence betokens consent.
        Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco.
          Ah, I see. I was thinking "why would a person who accidentally stringified a reference need to do this?", but now I realize that, because this technique now exists, you might stringify it intentionally.
          _____________________________________________________
          Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
          How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart