Re^10: Techniques On Saving Memory
by BrowserUk (Patriarch) on Mar 10, 2005 at 18:18 UTC
|
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.
| [reply] |
|
|
Ok, I'm game. So, should I work on this as Devel::RecoverRef (or some other, more appropriate name), or should I contact the authors of the Devel::Pointer* modules?
_____________________________________________________
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
| [reply] |
|
|
I would antisipate some resistance to the idea from some quarters, although most, if not all of the functionality is already exposed through a collection of other modules, and is obviously available to XS programmers anyway.
I'd do it as your own module. As for a name, maybe Devel::Reference?
Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
| [reply] |
|
|
japhy,
I think we should keep code reuse in mind here. Writing code that solves a specific task often involves intermediate steps. Divorcing the intermediate steps from the specific task allows others to reuse the intermediate steps for their specific task.
In other words, BrowserUk and I would both like to see a canned solution that would allow someone to stringify a reference, keep the memory around until needed, allow us to convert the string back into a reference, and release the memory when finished. This is unlikely going to be very useful to the general public, but some of the intermediate steps might be. I say 2 modules, 1 that provides all the XS basics and the second that ties them together for the specific task outlined above.
As BrowserUk mentioned elsewhere in this thread. Even the implementation I proposed doesn't mean you can't get into trouble easily.
| [reply] |
|
|
|
|
|
|
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.
| [reply] |
|
|
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.
| [reply] [d/l] |
|
|
|
|
|