Re: Indy components on the fly vs. on the form?

Giganews Newsgroups
Subject: Re: Indy components on the fly vs. on the form?
Posted by:  Remy Lebeau (TeamB) (gambit…@yahoo.com)
Date: Tue, 30 Sep 2003

"Andrew Fiddian-Green" <andrewfg at zugernet dot ch> wrote in message
news:167C99E3D680E240andrewfg at zugernet dot ch...

> My application uses IdHTTP client components for several
> different functions. Currently I create the components on the
> fly in code.  But I notice that Indy executes stack initialisation
> code only when the first component is created. So I suppose
> that if I create and destroy many Indy components on the fly
> this initialisation code may be run rather often. => Is there a
> performance hit?

No.  The only performance hit will be in the few CPU cycles it takes for the
CPU to compare a pointer value to 0.  The stack instance is assigned to a
global pointer when it is created.  If the pointer is nil when it is
checked, then the stack is created and assigned to the pointer.  After that,
all checked of the pointer will not be nil and the stack is not re-created.
Thus, there is no performance hit since nothing actually happens.  You'll
get a bigger performance hit by simply creating-destroying-recreating the
HTTP object itself often, as memory allocations and constructor/destructor
callings take more time than checking a pointer value.

Actually, looking at the latest TIdComponent code now, it appears that
someone re-wrote it at some point to use a critical section and reference
count instead of just checking the global pointer directly.  It wasn't
always like that.  So, there will be a slight performance hit in acquiring
ownership of a critical section, but not much.

Gambit

Gambit

Replies

In response to

Indy components on the fly vs. on the form? posted by Andrew Fiddian-Green on Tue, 30 Sep 2003