A closure prevents a variable from being GC'd when it goes out of scope by increasing the ref count.
I know what closures are and how they work. I'm asking how you are going to fake a closure?
I was trying to change a HoA into a regular hash ...
And I was ignoring the outer level of your individual problem and concentrating upon the core detail of how to store references in a packed string 'array'. As soon as you smash the reference, Perl no longer has any knowledge that you have a reference, so if the thing the caller passed to you that you have taken (and smashed) a reference to, goes out of scope in the callers code, Perl will feel free to GC it.
To avoid that, you would need to keep a copy of the unsmashed reference around. To do that, you need to put it somewhere:
The problems with that are.
Not my goal. ... ... ...
The Ho... bit doesn't matter. It could equally be an AoAs or an HoAoHoAs etc.
The main part of your original problem description is how to replace an array with a packed string, regardless of where the array/packed string will itself be stored.
And, as you pointed out, the problem with packing an array, is that it only really works with numeric values.
Storing the address of a reference to the actual data item neatly deals with that--except now how do you ensure the survival of the referred to item as you only have a smashed reference to it, and perl doesn't know you have it? See above.
I get the feeling that we are talking past each other here, but I will say that I've given this a lot of thought and code over the past two years, and I haven't discovered the magic ingredient yet. If you do, I'll be the first to congratulate you.
However, that none of the prolific p5p guys has implemented a complete compact array solution yet, given their great knowledge of the internals, makes me feel a little better about not having found the solution. I probably would have coded my germ of an idea by now, were it not that I feel that this can only be done by writing XS code--possibly including a patch to the core--and I find doing anything at that level, an exercise in total frustration. There are obviously good techniques for developing at that level, I'm just not party to them; haven't found the roadmap to doing it; and don't see any great willingness on the behalf of those in the know, to sharing their knowledge.
In reply to Re^5: Techniques On Saving Memory
by BrowserUk
in thread Techniques On Saving Memory
by Limbic~Region
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |