Link to home
Start Free TrialLog in
Avatar of pede
pede

asked on

out of resources

Hi

I have a pretty big application which uses quite a lot of bitmaps. The problem is that after running for a while, win95 runs out of resources, and I get a message that I cant draw on canvas. This does not happen on NT.

Isnt it pretty likely that its caused by the amount of bitmaps? I dont know for sure how many there is, maybe 50 or so... I find it strange, though, that it only happens after a while. Its not possible just to sit down and recreate the crash.

Good advice wanted. It might not be possible to cut any bitmaps out. Not even to collect them in a bitmap list (cant remember the component name right now).

Regards,
Pede
Avatar of Madshi
Madshi

You can download the little tool "ShowRes" from my homepage:

http://beam.to/madshi

This program shows you exactly the resources, win95 has problems with. And yes: A lot of bitmaps brings win95 to its knees. Why can't you use a TImageList instead? That's the common solution! How many forms does your project have? Do you let Delphi create them (look in your project for Application.CreateForm) or do you create them yourself?

Regards, Madshi.
What about using a different file type, like JPG or GIF.  They are a heck of a lot smaller and might be a solution.  (and if it isn't just ignore me.. hehe)

-Pal
Hi Pal,  :-)  this kind of resources is only about restricted handles, not about memory. Look at the documentation of the "CreateWindow" API:

Windows 95: The system can support a maximum of 16,364 window handles

Okay, here we're talking about GDI resources, but it's the same. Each bitmap takes one (or more) GDI handle(s), it doesn't matter how large the bitmap is or whether it is JPEG or GIF or uncompressed...

Regards, Madshi.
ooooh,  I see.  Hmmm.  Well then, how about using an ImageList, or even simpler, placing all the images on the HD and load/free them as needed?

(btw, 16,364 is a lot of handles... Though I am sure others have run into this same problem before.. What other common solutions are there?)

-Pal
Yes, the common solution is an ImageList, because an ImageList consumes only 1 handle (or 2, if it has a mask), independent on how many bitmaps it holds.
16K sounds like a lot, but that's not per application, but per system. And when Windows is started, you only have about 12K or so left.
My biggest Delphi project consumed >60% of the system resources in the beginning. So I replaced all the bitmaps by an ImageList and created the forms only when needed. Now it "only" consumes about 10%. That's still quite much, but I can live with it.
This handle thing is new to me let me see if I understand a little better..

Does each Component on an application consume a handle of its own?  So if you have 50 radio buttons each one has a handle.. (thus the invention of the RadioGroup box... which I assume only uses one.)

etc?



Each component that derives from TWinControl consumes (at least!) one handle. Components that derive from TGraphicControl (I think that was the name) do normally NOT consume a handle (except when they have a bitmap property, but then the bitmap consumes one handle, not the component itself). Some components consume more than one handle. I guess, a RadioGroupBox consumes one handle per radio button...
P.S: Under winNT (or Linux or BeOS) we don't have such handle restriction. That's a win9x problem...
Hmmm the more I think about it the more I realize what a large restriction it is..

-Pal
Is Handles the only thing that consumes system resources ?

It there are way to detect how many handles a form consumes ?
>> Is Handles the only thing that consumes system resources ?

There are different kind of resources. The kind we're talking about here is the win9x handle restriction. And this kind of resource is only consumes by handles.
But there are other resources like memory or harddisk space or CPU usage or ...

>> It there are way to detect how many handles a form consumes ?

Well, there is a way to detect that exactly, but it needs some deep hacks. If you don't need to know it *exactly*, you should look at the system resources (either in Control Panel -> System, or by using my tool, link above) before and after you create that form. Simply put a message box in your project's sources before the "Application.CreateForm(TYourMainForm, YourMainForm)" line and after that. Then you can calculate how many resources your form (in %) consumes.
There's no definitive answer to this question as you haven't said what you're currently doing so here are a list of things to keep in mind:

1. Make sure you FREE your bitmaps when you're finished with them

2. Don't reload bitmaps into TBitmaps over existing ones - free the TBitmap then create it again

3. Avoid Run Length Encoded bitmaps (RLE) as the decompression method wastes resources like nobodies business
Hi TheNeil,

welcome to the EE-family...  :-)

Well, may I say one friendly request? Could you post a *comment* next time rather than an *answer*? Because before you there were already a lot of comments added in this question and we should let pede decide which answer (respectively comment) earned the points... So it's usual practise here in the Delphi forum to write only comment in such a situation. Of course you couldn't know that - especially because the other forums behave different.

Thank you...   (-:

Regards, Madshi.
Avatar of pede

ASKER

Hi

Thanks for all the comments, eventhough they werent all for me ;)

TheNeil is right, there is no definitive answer to this. But so far I've used Madshi's program, and it have been very useful. At least it makes it possible to see if the changes to the program have an effect or not. Please propose an answer Madshi, and you will get the points.

Regards,
Pede

ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oops, didn't realise how it all worked around here. Apologies to one and all etc etc etc

The Neil

PS Windows will have no problem creating the handles for 50 bitmaps so I think you're going in the wrong direction when you start messing around with handles and imagelists. It all helps of course but...
Hehe, you didn't need to apologize, you couldn't know that!   :-)