Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

executable is loaded and takes too much time

Status
Not open for further replies.

zvikorn

Programmer
Aug 6, 2003
17
0
0
US
Hi,
I am creating my controls(aprox. 1000 controls) in the application dynamically, with the 'new' operator when the form is created. I'm having some arrays of pointers for the instances, and some other structures.
The problem is that when I am running the application, it takes 20 seconds till it is all loaded and shown to the user. I am guessing it because of the 1000 'new' I'm doing.
While being loaded, the form has to create all the instances, etc'.
I tried to make it with a thread, and it helped a bit, but still slow. Any ideas what is done usually to solve this?
Thanks. I appreciate your answer.
zvikorn
 
What controls are you making 1000 of? That could be part of the reason it's so slow. Can you try something else instead of making all of those controls? For instance, are you actually displaying 1000 controls on the screen at a given time?

If you are only displaying 10 of the controls at any given time, just use those 10 and create an emulation layer that the user won't even notice. You use the same 10 controls to display different data, and, if you're using a scrollbox, just update which controls are what and what their captions are when the user scrolls the box. You can assign a tag to each control to help in the discerning of what each one is when you are ready to utilize all of the data collected from them. You can still store the "value" of the controls in a 1000 size data structure, but it won't take a fraction of the time to access that.

Consider this example:

bool Checks[1000];

void __fastcall TMyForm::FormShow(void)
{
CheckBox1->OnChange = SetValue;
CheckBox2->OnChange = SetValue;
...
CheckBox10->OnChange = SetValue;
ScrollBox1->Max = 1000;
}

void __fastcall TMyForm::ScrollBoxChange(etc.etc.etc)
{
AnsiString asTemp = "CheckBox #";
asTemp += ScrollBox1->Position;
CheckBox1->Caption = asTemp;
CheckBox1->Tag = ScrollBox1->Position;
asTemp = "CheckBox #";
asTemp += ScrollBox1->Position + 1;
CheckBox2->Caption = asTemp;
CheckBox2->Tag = ScrollBox1->Position + 1;
etc...
CheckBox10->Caption = asTemp;
CheckBox10->Tag = ScrollBox1->Position + 9;
}

void __fastcall TMyForm::SetValue(TObject *Sender)
{
Checks[CheckBox1->Tag] = CheckBox1->Checked;
Checks[CheckBox2->Tag] = CheckBox2->Checked;
...
Checks[CheckBox10->Tag] = CheckBox10->Checked;
}

Hope this at least gives you an idea on how to reduce the memory usage and processor utilization.

Good luck,
Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top