in reply to Re: Space taken by a coderef
in thread Space taken by a coderef
My immediate thought is for flyweight objects that take more than one scalar's worth of info. Instead of using class-level parallel arrays to keep the info, I was thinking that, maybe, closures would be more memory-efficient. (This is over arrays or hashes.)
Now, yes, I know that optimizing for memory isn't necessarily a good thing, especially this early in the game. But, I just want to keep my options open and see what the comparison is.
An example of what I'm talking about would be:
sub new { my $class = shift; return undef if ref $class; my ($first, $second) = @_; my $self = sub { my $var = shift; my ($mode, $newval) = @_; if ($var == 0) { return $mode ? $first = $newval : $first; } elsif ($var == 1) { return $mode ? $second = $newval : $second; } return undef; }; bless $self, $class; return $self; }
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Space taken by a coderef
by chromatic (Archbishop) on Jan 19, 2002 at 00:53 UTC | |
by dragonchild (Archbishop) on Jan 19, 2002 at 01:28 UTC | |
by chromatic (Archbishop) on Jan 28, 2002 at 06:15 UTC |