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

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

Replies are listed 'Best First'.
Re^8: Techniques On Saving Memory
by BrowserUk (Patriarch) on Mar 10, 2005 at 17:46 UTC

    Devel::Pointer has a deref() function, which allows you to get you hands upon the address without literally stringifying it. What you loose, is the type and blessedness information. If you can get that all in a single call rather than messing around with parsing the stringified representation that would just make things simpler.

    The other side is if it is possible to recover that information from the SV pointed at, rather than having to store it and related it back later when you unsmash it, that would make life a great deal easier and remove another level of storage requirement and lookup.

    With both sides, plus the appropriate refcount manipulations, you have the possibility to retain a single 32-bit value as a handle to anything. That makes the whole compact array idea almost practical.


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco.
      You don't lose the type and blessed information, per se. The address, when turned back into a reference, regains that data, if you do it the way I did it in my XS code: RETVAL = newRV((SV *) addr); Doing it like that restores the reference fully.

      What I don't get, though, is what this is good for. The memory for the data structure must still be allocated. In which case, why not just use a reference (which is an SV) instead of a number stored in an SV?

      _____________________________________________________
      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

        Because you can concatenate a million 32-bit numbers into a single, (4 MB) SV, and avoid having to allocate the other 999,999 SVs which would require 12 MB minimum, and over 220 MB if they were all blessed references and you put them into an array. And much more if you put them into a hash for fast lookup.

        A packed string of equal sized elements has all the properties of an array. Very fast indexing and the ability to be spliced. And it uses a huge amount less memory.


        Examine what is said, not who speaks.
        Silence betokens consent.
        Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco.