G
grocery_stocker
Given the following:
#!/usr/bin/perl -w
package Person;
sub new {
my $that = shift;
my $class = ref($that) || $that;
my $self = {
NAME => undef,
AGE => undef,
PEERS => []
};
my $closure = sub {
my $field = shift;
if (@_) { $self->{$field} = shift }
return $self->{$field};
};
bless($closure, $class);
return $closure;
}
sub name { &{ $_[0] }("NAME", @_[ 1 .. $#_ ] ) }
package main;
$him = Person->new();
$him2 = Person->new();
$him3 = Person->new();
$him->name("my ex girlfried");
$him2->name("is a");
$him3->name("whore");
print $him->name, "\n";
print $him2->name, "\n";
print $him3->name, "\n";
This presumably creates 3 hashes. If I modified this to create say like
30,000 hashes, this could possibly blow.
Okay, if modified the code to have something like:
use Symbol;
$obj = Symbol::gensym();
vs
my $self = {
NAME => undef,
AGE => undef,
PEERS => []
};
Would I still be creating more memory each time I invoked a new
instance of the object?
#!/usr/bin/perl -w
package Person;
sub new {
my $that = shift;
my $class = ref($that) || $that;
my $self = {
NAME => undef,
AGE => undef,
PEERS => []
};
my $closure = sub {
my $field = shift;
if (@_) { $self->{$field} = shift }
return $self->{$field};
};
bless($closure, $class);
return $closure;
}
sub name { &{ $_[0] }("NAME", @_[ 1 .. $#_ ] ) }
package main;
$him = Person->new();
$him2 = Person->new();
$him3 = Person->new();
$him->name("my ex girlfried");
$him2->name("is a");
$him3->name("whore");
print $him->name, "\n";
print $him2->name, "\n";
print $him3->name, "\n";
This presumably creates 3 hashes. If I modified this to create say like
30,000 hashes, this could possibly blow.
Okay, if modified the code to have something like:
use Symbol;
$obj = Symbol::gensym();
vs
my $self = {
NAME => undef,
AGE => undef,
PEERS => []
};
Would I still be creating more memory each time I invoked a new
instance of the object?