views:

52

answers:

3

There's a registry key where I can check (& set) the currently set GDI object quota for processes. However, if a user changes that registry key, the value remains the old value until a reboot occurs. In my program, I need to know if there's a way to determine, programatically, how many more GDI objects I can create. Is there an API for getting GDI information for the current process? What about at the system level?

+2  A: 

Always hard to prove the definite absence of an API, but this one is a 95% no-go. Lots of system settings are configured through the registry without an API to tweak it afterward.

Raymond Chen's typical response to questions like these is "if you want to know then you are doing something wrong". It applies here, the default quota of 10,000 handles is enormous.

Hans Passant
My application is capable of opening very, very large MDI documents with various sub documents. There are situations where we reach the GDI object limit. I'm trying to figure out what the limit is, so that I can tell if a user is getting close to the threshold and not allow them to open any further documents. I'd prefer to do it before the GDI exception is thrown.
Mike Caron
It doesn't make a lot of sense, your screen doesn't get bigger. You'd better go leak hunting, it's so easy to leak with MFC. Google 'gdileaks.exe'.
Hans Passant
Yeah, that's great for a long term solution, but I want to prevent customers from getting to the quota limit now, in the short run. That enables me to fix leaks without making customers angry because of software crashes.
Mike Caron
Wow, painful. Did they actually get that desperate that they are hacking the registry? No wonder they are angry, better make that a short term goal. Obviously adjusting the registry setting while the program is running has no effect so just tell them to stop doing that. And your "I'm about to crash" message box would be accurate.
Hans Passant
Thanks for your feedback, Hans. Much appreciated.
Mike Caron
A: 

Since Hans mentioned Raymond already, we should play his "Imagine if this were true" game. If this API - GetGDIObjectLimit or whatever - existed, what would it return? If the object count limit is 10000, then you expect it to return that right? So what happens when the system is low on memory? The API tells you a value which has no actual meaning. If you're getting close to 10000 GDI objects, you are doing something wrong and you should concentrate on fixing that.

Stewart
This doesn't answer the question. Regardless, getting to 10000 doesn't necessarily mean one is doing something wrong. Suppose your application is capable of launching many documents at a time and a parent document references all of these. If you're on x64 with 16 Gb of RAM, it's quite tangible to reach this. Take Araxis merge for example. You could open a folder compare of two DVDs filled with data and reach the limit VERY fast.
Mike Caron
Fair point, it doesn't answer the question. If you are running on an OS which has a limitation of 10000 objects, and you hit that limit, you are doing something wrong. Now, if you were running on a different OS that didn't have that limitation then you're just fine. The questioner is not using that OS though.
Stewart
+1  A: 

If you want to find the current quota that matters to you, create GDI objects until that fails. Record that number. Then, destroy all of them.

If you feel like doing this on a regular basis to get an accurate number, you can do so. It's probably going to be fairly expensive though.

MSN
Accepted because it explicitly answers the question asked.
Mike Caron