E
ed
Hi all. I need to create a script that is always going to be running.
So I guess pretty much everything is going to be taking place inside
of
one main loop.
If I use objects that are lexically scoped within that loop, it means
that
new objects have to be created at the beginning of every iteration.
Would using objects be much slower than just calling sub routines?
If the answer to that is yes. I wonder if one solution(as a way to
still use OOP)
would be to extend my classes and create a "clear()" method or
something similar
that would basically set my object back to an uninitialized state.
Then I reinitialize it at the top of the loop and use it as if it were
a new
object.
Example:
my $obj = new Obj;
while (!$done)
{
$obj->initialize('param1', 'param2');
$obj->doSomething();
$obj->doSomethingElse();
$obj->clear();
}
As opposed to:
while (!$done)
{
my $obj = new Obj('param1', 'param2');
$obj->doSomething();
$obj->doSomethingElse();
}
-----
Note: In a real situation the parameters to the objects will change
with
every interation. I just wanted to keep the examples simple.
----------
Would using the first example speed things up substantially?
Would it still be substantially slower than if I were just calling sub
routines
instead of creating objects?
Is object creation quick enough in perl that I should not even worry
about it?
tia,
--ed
So I guess pretty much everything is going to be taking place inside
of
one main loop.
If I use objects that are lexically scoped within that loop, it means
that
new objects have to be created at the beginning of every iteration.
Would using objects be much slower than just calling sub routines?
If the answer to that is yes. I wonder if one solution(as a way to
still use OOP)
would be to extend my classes and create a "clear()" method or
something similar
that would basically set my object back to an uninitialized state.
Then I reinitialize it at the top of the loop and use it as if it were
a new
object.
Example:
my $obj = new Obj;
while (!$done)
{
$obj->initialize('param1', 'param2');
$obj->doSomething();
$obj->doSomethingElse();
$obj->clear();
}
As opposed to:
while (!$done)
{
my $obj = new Obj('param1', 'param2');
$obj->doSomething();
$obj->doSomethingElse();
}
-----
Note: In a real situation the parameters to the objects will change
with
every interation. I just wanted to keep the examples simple.
----------
Would using the first example speed things up substantially?
Would it still be substantially slower than if I were just calling sub
routines
instead of creating objects?
Is object creation quick enough in perl that I should not even worry
about it?
tia,
--ed