in reply to Re: Techniques On Saving Memory
in thread Techniques On Saving Memory
tye was quick to point out an easy solution for the problem was to use a parallel hash as a lookup table. I admitted it was a good straight forward answer but defeated my purpose. On the other hand if an anonymous sub can be made to take up less space than the anonymous array:
sub compact { my $ref = shift; my $pck; # Packed information except reference # purposefully avoiding dispatch table # This keeps us at HoC return sub { if ( $_[0] eq 'data' ) { return $ref }; elsif ( $_[0] eq 'blah' ) { return unpack('A1', $pck) } # where each unpack format gets desired data }; } $hash{foo} = compact( [1..10] ); $hash{foo}->( 'data' )[3] = 42;
The interface could use work and it doesn't really explore any uncharted territory for me. It also is still not a single hash. We are just trading anonymous subs for anonymous arrays.
Cheers - L~R
|
|---|