|
While I have tried to optimize OIO whenever possible, the rapid generation and destruction of many objects is a bane for OIO. If the objects are trivial in nature, perhaps just using ordinary hash-based objects would make more sense. Another option might be to use a "recycling bin" for objects:
package MyClass; {
use Object::InsideOut;
my @myattr :Field :Std(myattr);
# Class specific object recycling
my @recycle_bin;
sub GetObj
{
return (pop(@recycle_bin)) if (@recycle_bin);
return MyClass->new();
}
sub Recycle
{
push(@recycle_bin, shift);
}
}
package main;
MAIN:
{
# Get a new or recycled object
my $obj = MyClass::GetObj();
# Initialize object
$obj->set_myattr(27);
# Use object
print $obj->get_myattr(), "\n";
# Recycle object
MyClass::Recycle($obj);
}
The above limits object initialization, but doubtless it could be improved upon.
I cannot comment on Moose's immutable option because I do not know how Moose manages objects and their methods. |