• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 506
  • Last Modified:

Efficient programming

Hi.

Our Application is an delphi ISAPI Dll .
The Client and Server has forms and the
Client has forms rich in window controls
and graphical controls.We get the "Out
of memory" error and Access violation in WINDOWS 98
when we open just 6 forms.
This is due to the limitation of Windows 98.
It's working in Windows NT/2K
Is there a workaround in delphi to avoid
such errors? I tried to design the form
with many tab pages.This reduced the use
of system resources but once we enter into
the graphical tab page the resource consumption
is more and is not regained when the tab page is
out of focus.
Is there any efficient way of programming in delphi?

Thanks and Regards
Prema
0
premaa
Asked:
premaa
  • 10
  • 8
  • 3
  • +1
1 Solution
 
MadshiCommented:
>> Is there any efficient way of programming in delphi?

Oh, yes, of course...   :-)

Well, in win9x you have 3 kind of resources:
(1) GDI resources (bitmaps, brushes, pens, ...).
(2) System resources (process, thread, semaphore, file, ...).
(3) User resources (windows, window stations...).

All those resources are nothing but handles. Win9x can handle 16k of those handles (if I remember correctly). If you use more, everything goes wild.

So that means, you have to be careful with all kinds of handles. Please check your sources, whether you release all handles, which you have opened. Furthermore try to avoid TPanel if possible, because each TPanel consumes one window handle. Instead use TBevel, it consumes no handles at all. Also avoid TImage and such stuff, because each of those components consumes 1 or even 2 (masked) GDI handles. Instead use image lists and bitmap/image components which work with image lists. Finally don't create all forms at once during the initialization, instead only create them if you need them and free them afterwards again.

If you follow all those tips, you should be able to significantly reduce the resouces consumation of your software.

Regards, Madshi.
0
 
premaaAuthor Commented:
Thanks for the immediate reply,
Only the system resources and GDI resources
goes up in this case..


is there any site that you know which
gives tips like these so that it'll be
helpful for us in future ..


Regards
Prema.
0
 
MadshiCommented:
Hmmm... Don't know such a site in the moment.

If user resources don't go up, you don't need to care for TPanel. System resources go up as well? Do they go down if you close your forms without closing the process (when closing the process Windows automatically releases all resources)?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
premaaAuthor Commented:
Yes, There are no memory leaks ,
But the system and GDI resources go up ,
For every form that is opened , 16% is used
for both the resource types ,
moving the graphical controls
to different tab pages is also not helping much.

Thanks & Regards
Prema.

0
 
SteveWaiteCommented:

I create and destroy forms on the fly if the form is not visible when not in focus. Also do the same with tabbed sheets, you cannot see the contents of the other tabbed sheets so destroy them and create them when they come into view.

Regards
Steve
0
 
MadshiCommented:
16% per window is absolute overkill. Which components do you have on the form?
0
 
premaaAuthor Commented:
Sorry that i could not post immediately,
was help up in a discussion.
Thanks Steve,Currently I have no idea
about how it's done as we
are going to maintain this product
developed by some other team.
The form has many buttons,controls and images.
THe user can also customize it . He can use
many images / controls as per his need.
When i searched in the files ,  i found
TPanels,TImage and Tbitmaps are used..
using Memproof also we found immense
use of bitmaps,windows etc..

Thanks and Regards
Prema

0
 
CrazyOneCommented:
Just one correction I would like to submit not that it helps your current situation but I thought I would pass on this info anyway.

"System resources are areas of memory that are used by the input manager (USER) and the graphic display interface manager (GDI) for keeping track of all of the windows that are open in a session and for drawing objects on the screen. Stored in memory in  these heaps and the size of each heap is fixed."

16-bit User heap (64K)
32-bit User window heap (2MB)
32-bit User menu heap (2MB)
16-bit GDI heap (64K)
32-bit GDI heap (2MB)
-------------------------

Also don't confuse system with being a separate resource. There are only two the USER and the GDI. The SYSTEM one just displays which one of the two that has the lowest percentage. So in this case your problem seems to stem from the GDI, which is the graphics interface. Try reducing the number of colors, pens, bushes, and fonts being used on/in the form and or in the application. Reuse redundant objects instead of creating separate individual ones.
-------------------------
 
"The USER heap contains information about windows being used by active applications. The data structure for each window, including any minimized windows, is stored in this heap. Examples of windows include application windows, dialog boxes, and controls (such as buttons and check boxes).

The GDI heap contains graphical objects, such as pens, brushes, cursors, fonts, and icons. " 
-------------------------

These links give some detail info about the System Resources although it has nothing to do with programming per se the information nonetheless could be useful.

http://www.windows-help.net/techfiles/win-resources.html
http://www.techweb.com/winmag/columns/explorer/2000/11.htm


The Crazy One
0
 
MadshiCommented:
Hi CrazyOne,

you seem to be right in saying that "system" just shows the lower of the other two. I always thought it would be a seperate resource, because there do exist 3 kinds of handles (GDI, user and kernel handles). So I always thought the "system" resource value would show the usage of kernel handles. But after thinking about it, this might be wrong. Kernel handles are quite different from the other 2 kinds, so it's very well possible, that there's no "kernel resource".

Regards, Madshi.
0
 
premaaAuthor Commented:
Thanks CrazyOne for that information regarding system Resource ,
Our application seems to use
lot of bitmap handles.
We found out using Memproof that bitmap and
window handles go up on opening a form depending
on the number and type of controls on the form.
Is there any way the form can be redesigned ?
Can u please let us know the alternate for TBitmap like u suggested
for TPanel..? Can you please give any more of such
tips ?

Thanks and Regards
Prema.








0
 
MadshiCommented:
Look, a TBitmap is an encapsulation of a Windows GDI bitmap. Same with TImage. This consumes 1 handle or 2 handles (if the bitmap has a mask) for each TImage. To save resources, 32bit Windows has introduced image lists. An image list can contain thousands of images and only consumes 1-2 handles, regardless of how many bitmaps it contains. However, all images in one image list have to have the same size and color depth.

There are free controls out there, which work more or less similar to TImage, but don't have a Picture property. Instead they directly work with a TImageList, so they consume no handles at all (only the image list).

Look on the well known Delphi freeware components pages (e.g. www.torry.net ). I'm quite sure there are several such components available.

Regards, Madshi.
0
 
premaaAuthor Commented:
Hi ,
May be using this TBitmap is the main problem.
Bcos more user resources are free than GDI
For one form , Memproof showed
LivePointer 10921
Global heap 41
Bitmaps 209
Brush 20
Palette 51
Window 177
These numbers go up once the form is loaded..

Thanks & Regards
Prema.
0
 
MadshiCommented:
Windows and Bitmaps are both too high, if you ask me...
0
 
premaaAuthor Commented:
Hi ,
Thanks for the immediate reply.
But the form has a number of controls.
May be this is bcos of the TPanel.
So , Instead of using TBitmap if we
use TImagelist will the number of handles
get reduced? Can we recommend this solution?


Thanks
Prema.
0
 
MadshiCommented:
I was recommending this solution already with my first comment...   :-)
0
 
CrazyOneCommented:
Hi Madshi

Yeah I think for some reason there isn't the same tight restrictions put on the kernel handles as there are for the other two. I am not sure why this is though.

premaa

I think Madshi may be correct in advising to use TImagelist to help reduce the handles. Try it and see what happens.

Sometimes depending on the application and what it is intended to do you sometimes can trim how much of the System Resources get use. However there are times that the application will cause a big hit on the System Resources and there is not much that can be done about it. It is not entirely unusual although somewhat rare to see a program use over 15% of the System Resources. Example take a look at how much Delphi uses on a complex application while your doing Step Over debugging. The main reason I switched to Win2000 was because when doing a lot of debugging in Delphi with Win98 the System Resources would steadily drop to the point that I had to close Delphi. Sometimes I had to reboot because sometimes not all of the Resources that Delphi had used would be released.
0
 
premaaAuthor Commented:
Hi,
 When we browsed Delphi help, we found a
method TBitmap.Dormant which frees GDI
resources ..Will it be useful? this is not used
in our code at all.
They have also used Timagelist.
Please let me know whether adding this
function will help

Thanks and regards
Prema
0
 
CrazyOneCommented:
Hmm never knew about that method before. I don't use a lot of BitMaps so I couldn't tell how effective the Dormant method would be but reading the help file it seem like the main function of it is to release the handle from the GDI. Sounds good to me. It may use more memory but chances that shouldn't be a big issue of course that all depends on the system it runs on and how many DIB's are being used and how many other programs are running at the same time.
0
 
MadshiCommented:
Just try it out. I'm not sure whether it helps. I think replacing the bitmaps would be a better choice.
0
 
premaaAuthor Commented:
Thanks , I'll try out and let u know by today..

Regards
Prema.
0
 
premaaAuthor Commented:
Hi ,
 There was some animation in my form , I was able to
open 2 more forms when i commented that part of code..
is there any property in Delphi tab page control
to create controls on the page dynamically only
when the user clicks, similar to "createondemand" property
in Powerbuilder.?

Thanks and Regards
Prema.
0
 
SteveWaiteCommented:
That's the idea!!
TPageControl.OnChange fires when you select a new tab. Have the controls created for the page then.
Regards,
Steve
0
 
premaaAuthor Commented:
Hi ,
 Is there any control that can host other controls
and take up less number of handles like the datawindow
in Powerbuilder.?

Thanks and Regards
Prema.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 10
  • 8
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now