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

This is exactly how an array is implemented. All you really want is to be able to set each element to be the alias of the appropriate SV in memory. Arrays, in memory, are just a blob of containing a list of pointers to SVs. You're just removing yourself from that by one in that instead of having your 4MB blob of pointers by known by perl as pointers, you treat it as a string, find the pointer you want, and get the pointer to be treated as such. There already modules out there for helping with the task you've just outlined and they'll solve it better than offloading it into user code.

Replies are listed 'Best First'.
Re^12: Techniques On Saving Memory
by BrowserUk (Patriarch) on Mar 11, 2005 at 16:46 UTC
    There already modules out there for helping with the task you've just outlined

    ?


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

      I've never needed to use this myself but this is what I've seen other people like demerphq use when working with aliases. You could then keep @foo around somewhere and it handles the details that the values in the variables exist at some other location (without having to use another reference) and because its an alias, would handle holding weakened references just fine. That's the theory anyway. If this module doesn't do it right, this is at least the right idea. The array is implemented as a C array of pointers so all this does it make your packed list of pointers "real" instead of faked in a string.

      use Lexical::Alias 'alias'; my $src; alias $src, $foo[ ... ]

        Sorry diotalevi, I'm sure you know what your getting at, but it's going right over my head.

        I don't see how Lexical::Alias has anything to do with what Japhy and I were discussing, and as Japhy wrote Lexical::Alias I would have thought that he would have recognised the correspondance if there was one.

        The last thing I need for my purposes is the creation of yet more perl internal structures and hash entries (pad entries) pointing to things that I don't have a first name for and couldn't use a second name for, even if they didn't involve using more space--which is exactly what I'm trying to avoid.


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