new always involve memory allocation which cost time.

Here is what I think might help to improve performance

original code

a = new blah
try
{
   a.stuff
   a.stuff
   a.stuff
}
 finally
{
   a.dispose;
}

b = new blah
try
{
   b.stuff
   b.stuff
}
 finally
{
   b.dispose;
}

------------

Modified code
a = new blah
try
{
   a.stuff
   a.stuff
   a.stuff

   a.recycle

   a.stuff
   a.stuff
}
 finally
{
   a.dispose;
}

-------------
Or more clean code

a = ResourceEngine.getInstance(TYPE_A);
try
{
   a.stuff
   a.stuff
   a.stuff

}
 finally
{
   ResourceEngine.releaseResource(a);
}

b = ResourceEngine.getInstance(TYPE_A);
try
{
   b.stuff
   b.stuff
}
 finally
{
   ResourceEngine.releaseResource(b);
}

ResourceEngine is maintained by application programmer, not os. Application
has more knowledge than os about how to reuse the data thus result more
performance. But nowdays communication cost seems more dear than computation
cost, so it might not be so important anymore.

Regards
Leigh
www.smootharm.com

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Paul Heinz
Sent: Friday, 21 July 2006 4:18 p.m.
To: NZ Borland Developers Group - Delphi List
Subject: RE: [DUG] Related try..finally question


Leigh wrote:

> I have done some coding and found that current issues for most programming
> is resource management i.e. memory allocation, TCP/IP connection
> allocation.
> If an application can manage resource well, the application will run very
> good. I am very relucant to give up this control to someone else to manage
> it. Delphi 7 gives me reasonable control over this sorts of issue. ;-)

I assume this is in reference to 'using' and .NET references implying
garbage collection.

Firstly, 'using' as a C# language semantic is distinct from garbage
collection.

using (a = new blah)
{
   a.stuff
   a.stuff
   a.stuff
}

is purely syntactic sugar and equivalent to:

a = new blah
try
{
   a.stuff
   a.stuff
   a.stuff
}
 finally
{
   a.dispose;
}

Manual (i.e. Delphi style) memory management (which is what garbage
collection resolves - other resources must still be managed as usual) is
overrated in my opinion. A well designed precise generational garbage
collector does just as good a job overall of managing memory as a developer
manually coding it, likely better if your object lifetimes and
interrelationships are complicated and your developer didn't miss anything.

In fact, in anything like the SQL parser, optimiser, and execution engine we
built, you end up spending a goodly chunk of your engineering and debugging
time writing fiddly lifetime management code i.e. a domain specific mini-
garbage collector anyway.

TTFN,
  Paul.



_______________________________________________
Delphi mailing list
[email protected]
http://ns3.123.co.nz/mailman/listinfo/delphi


_______________________________________________
Delphi mailing list
[email protected]
http://ns3.123.co.nz/mailman/listinfo/delphi

Reply via email to