Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

System Resources

Posted on 1999-07-17
17
Medium Priority
?
226 Views
Last Modified: 2012-05-04
When I run my application the System Resources drop dramatically. If I start with System Resources of say 90% I run my app and the System Resources drop down to as low as 48%. This also happens while working on the app in Delphi IDE which causes obvious problems i.e the System Resources have dropped to 48% I try to run the app from within Delphi - BANG cpu errors hangs etc.

My app compiles to about 1.6MB there are a few images in there and a PageControl with around 12 TabSheets. Where am I going wrong with using so much System Resources? Any suggestions?
I'm using D4 Win98

Hopefully
Chris
0
Comment
Question by:xpher
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 4
  • +2
17 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 1389276
i dont think you got too much to worry as about my system resources are down to 43% with delphi open and only a button and a memo on the form..
0
 
LVL 17

Expert Comment

by:inthe
ID: 1389277
closed outlook express got 47% now..
0
 
LVL 1

Author Comment

by:xpher
ID: 1389278
Mmmm trouble is I get problems with messages like can't draw on canvas (running app without Delphi open) and I haven't done anything as far as drawing or making changes to canvas, and then my machine starts to lock up. When you have Delphi open and System Resources at 47% can you actually run your app from Delphi with no problems? I ask cos' I wonder if there is a problem with my system, I've just installed a Rainbow Runner card and also upgraded from 64MB RAM to 128MB RAM.

Cheers
Chris

ps My worry is also if app is used on anpther machine it may cause problems.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:simonet
ID: 1389279
How are you calculating the system resources? WHat program are you using?

Alex
0
 
LVL 17

Expert Comment

by:inthe
ID: 1389280
i have no trouble running apps etc from delphi ..
i dont believe my resource program anyway (microsoft one)
Did you have any trouble before the upgrade?
0
 
LVL 1

Author Comment

by:xpher
ID: 1389281
Hi Alex
I'm using Performance tab from Win98 System Properties. (Right click MyComputer etc.)

Regards
Chris
0
 
LVL 17

Expert Comment

by:inthe
ID: 1389282
i'd get some decent programs like norton utilities or sisoft sandras to see what they say.
when using these i now have much better resources than with the win98 performance tab.

0
 
LVL 15

Expert Comment

by:simonet
ID: 1389283
Chris,

I wouldn't worry about it. When you're working on the IDE, you have to remember that Delphi also takes up a lot of resources, including many hidden windows (forms).

However, there are tricks we can use to optimize resource usage:

1) Use TBevel instead of TPanel. I've seen many people using a TPanel when alll they want to do is to create a nice border effect. Use TPanel only if you want to create borders AND have a container for the components. TPanels use a lot more resources (including GDI resources) than TBevel.

2) Create your forms by hand. Don't let Delphi "auto-create" the forms for you (the default behaviour) you should create and free your own only forms when needed.

3) If possible create other objects in runtime too, and free them when no longer needed.

4) Do not waste variables. If you can optimize the usage of variables, you'll not only saving system resoruces, but also optimizing the overal performance of the application.

5) Do not inherit your components from a class whose features will not be needed. For example: suppose you're creating a new class that will only be created in runtime and is not visual. In this case, there's no need to inherit it from TComponent. Inherit from TPersistent or TObject, whichever lowest level best suits your need. The lower the hierarchy level of the "parent class", the best.

Other good sites to check, for both resource optimizations and performance optimzation are:

http://www.drbob42.com/delphi/perform.htm
http://www.econos.com/optimize/

Lots of info here: http://inner-smile.com/delphit.htm

Yours,

Alex
0
 
LVL 15

Expert Comment

by:simonet
ID: 1389284
BTW, as of the images in your applications, I advise you to move them all to resources (check my site in order to know how to do that) and only load them when needed.

Yours,

Alex
Athena's Place: http://www.bhnet.com.br/~simonet
0
 
LVL 1

Author Comment

by:xpher
ID: 1389285
Hi Alex
Thanks for info. I have done much of what you say but can you enlighten me more on point 2)Create your forms by hand.

Cheers
Chris
0
 
LVL 15

Expert Comment

by:simonet
ID: 1389286
What I mean was not to let all the forms in your project(s) be autocreated. See, when you add a form to a project, Delphi automatically adds code the the project source that makes that form be autocreated when the application is run. This way, when the application is run, it will take a lot longer to start, it will take up a lot more resources, and it's not code efficient.

What you must do is to create the forms only when you need them. Let me show you what I mean:

- Suppose I just created a new application in Delphi. I have Form1, which is my main form. Suppose I want to add another form, which will be called by form1 on the click of a button. If I do as Delphi suggests, my project source will look like this:

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.

In the code above, Form2 will be create when the application is run, and all the memory it takes will be being consumed at all times, even when the form is not being shown or used.

the solution for the problem raised is to go to the Project Options and not let Form2 be an autocrated form. SO, whenver you need to use Form2, you can create it yourself, like this:

procedure TForm1.Button1Click(Sender : TObject);
begin
   if not assigned(Form2) then
     Form2 := TForm2.create(application);
   Form2.show;  // or showmodal... whichever fits your needs best
end;

Of course there are exception to this rule, but they are exceptions and experience will tell will in what cases an autocreated for is better than a runtime-created form

When working with runtime-created forms, make sure you dispose/free/release them when you're done using them (does this bring you memories from when you were in your early 20's ?! It does to me!)

Yours,

Alex
0
 
LVL 1

Author Comment

by:xpher
ID: 1389287
Hi Alex
Yes it does ;)

I will have alook at what you have just said.

Out of interest I have laid my hands on a Component Writers Guide for D1. In this book it says "..Windows doesn't know about graphic controls. They have no window handles, and therefore consume no system resources."

Cheers
Chris
0
 
LVL 15

Expert Comment

by:simonet
ID: 1389288
That's perfectly right. Only descendants from TWinControl have handles. However controls that don't have handles are taking up other kinds of resources (like User resources).

Besides, if they have a canvas, they are also taking GDI resources.

Remember that there are 3 kinds of resources:
System, User and GDI

Yours,

Alex
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1389289
Hi guys,

Alex is right with all his suggestions. Just one addition: If you have some bitmaps in your forms, try to put them into a TImageList. Each and every bitmap consumes 1 handle. One ImageList consumes 1 handle, too, doesn't matter how many bitmaps are in the ImageList.
If you want to see the resources all the time, you can download "showRes" from my homepage "http://beam.to/madshi". It simply opens a little stayOnTop window at the bottom right corner of the screen.
BTW, with Outlook and Internet Explorer and Delphi4 my resources are at 57%...

Regards, Madshi.
0
 
LVL 3

Expert Comment

by:y2kwacko
ID: 1389290
check out:
http://www.undu.com/helpmakers/samp_html/50500_winapi.html

File: FreeResources_1

Relation: [ WinApi ]
Size: 28 KB

Author: Jim Seach
 
Info: Freeing Windows Resources on the fly in Delphi

0
 
LVL 1

Author Comment

by:xpher
ID: 1389291
Well I am overwhelmed with all your help and ideas on this one, I am just sorry it is so little points but as with the rest of my life I'm broke.

Like the ShowRes 1.0 Madshi well useful.

Using Alex's idea of 'Create forms by hand' and a little re-designing the problem now seems to be solved. Running the app from within Delphi brings the System resources down to about 40%. If I run the app without Delphi the System resources drop from around 90%ish to around 72% which I don't think is too bad at all.

Would you like to post an answer Alex?

Once again thanks to all

Cheers
Chris :))
0
 
LVL 15

Accepted Solution

by:
simonet earned 80 total points
ID: 1389292
Thank you Chris. 'Glad I could help.

Have a nice Sunday!

Alex
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question