Multiple CDC::SelectObject()
-
No it is not safe to use.It will cause memory leak in your application. I think,II Option is better one.Use SelectObject(m_pOld)/DeleteDC() after each SelectObject(&some_bitmapX)??
priyank
I have already tried both versions. None of them reports memory leaks in VS2003 in Debug mode. But maybe those resources are not monitored by VS... That's why I'm askng:) Thanks!
-
No it is not safe to use.It will cause memory leak in your application. I think,II Option is better one.Use SelectObject(m_pOld)/DeleteDC() after each SelectObject(&some_bitmapX)??
priyank
pri_skit wrote:
No it is not safe to use
Its safe.. its nothing to do with leaks (if we delete the selected objects) or simply we can do like this,
CDC dc;//assign value
dc.SaveDC();
/*
* Do select object,
* or what ever you want.
*/
dc.RestoreDC( -1 );No need to worry about the old objects..
Do your Duty and Don't expect the Result
-
pri_skit wrote:
No it is not safe to use
Its safe.. its nothing to do with leaks (if we delete the selected objects) or simply we can do like this,
CDC dc;//assign value
dc.SaveDC();
/*
* Do select object,
* or what ever you want.
*/
dc.RestoreDC( -1 );No need to worry about the old objects..
Do your Duty and Don't expect the Result
Yes, I delete some_bitmapX objects (when exiting the app as they are 'global'). What I care about is: 1) Performance 2) Avoid memory/resource leaks. Is CDC::CreateCompatibleDC()/DeleteDC() slower comparing to CDC::SaveDC()/RestoreDC()?? Thanks for help.
-
Yes, I delete some_bitmapX objects (when exiting the app as they are 'global'). What I care about is: 1) Performance 2) Avoid memory/resource leaks. Is CDC::CreateCompatibleDC()/DeleteDC() slower comparing to CDC::SaveDC()/RestoreDC()?? Thanks for help.
-
Yes, I delete some_bitmapX objects (when exiting the app as they are 'global'). What I care about is: 1) Performance 2) Avoid memory/resource leaks. Is CDC::CreateCompatibleDC()/DeleteDC() slower comparing to CDC::SaveDC()/RestoreDC()?? Thanks for help.
PatrykDabrowski wrote:
I delete some_bitmapX objects (when exiting the app as they are 'global').
If you are creating those object once and deleting at the end, then no problem.
PatrykDabrowski wrote:
CreateCompatibleDC()/DeleteDC() slower comparing to CDC::SaveDC()/RestoreDC()??
These two set of APIs are different from each other. That is, after creating a compatible DC, you have select the needed objects into the DC. At last the original object belong to the DC have to be selected (the object returned, at the first select object, note this appicable for that specific type of object). DelectDC will delete the DC that you created. But the SaveDC and RestoreDC is for making the DC to its original state, you need not worry about reselecting the original objects. see below;
CDC dc; dc.CreateCompatibleDC(..);
dc.SaveDC();
dc.SelectObject(bitmap1); /* do something */
dc.SelectObject(bitmap2); /* do something */
dc.RestoreDC( -1 );
dc.DeleteDC();By doing so, you need not have to maintain the old objects returned.
Do your Duty and Don't expect the Result
-
Please revise the order of your list :):-D:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
CPallini wrote:
Please revise the order of your list
:laugh: so true !
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
CPallini wrote:
Please revise the order of your list
:laugh: so true !
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
I should put 1) && 2)...in fact as long as I dont have leaks, I care more about performance:) So the order is fine:)
-
I should put 1) && 2)...in fact as long as I dont have leaks, I care more about performance:) So the order is fine:)
PatrykDabrowski wrote:
I care more about performance:) So the order is fine:)
so, you prefer allocating some memory, even if you "can't" delete it, until it doesn't affect your performances ? dude, you're not alone running on the system ! what if everybody was coding like this - letting memory leaks voluntarily - because it "doesn't affect the perfrmances of the application" ?? :wtf: you should always care about leaks first (of course, thinking of not coding too dirtily, of course) and optimize only then, if necessary...
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
PatrykDabrowski wrote:
I care more about performance:) So the order is fine:)
so, you prefer allocating some memory, even if you "can't" delete it, until it doesn't affect your performances ? dude, you're not alone running on the system ! what if everybody was coding like this - letting memory leaks voluntarily - because it "doesn't affect the perfrmances of the application" ?? :wtf: you should always care about leaks first (of course, thinking of not coding too dirtily, of course) and optimize only then, if necessary...
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
I have written "as long as I dont have leaks, I care more about performance:)";)...so my priority is to avoid memory leaks and then I optimize my code. I assume that both solutions don't cause leaks so I would like to choose faster one. (I mean CDC::CreateCompatibleDC()/DeleteDC against CDC::SaveCD()/RestoreDC() )
-
I have written "as long as I dont have leaks, I care more about performance:)";)...so my priority is to avoid memory leaks and then I optimize my code. I assume that both solutions don't cause leaks so I would like to choose faster one. (I mean CDC::CreateCompatibleDC()/DeleteDC against CDC::SaveCD()/RestoreDC() )
PatrykDabrowski wrote:
I have written "as long as I dont have leaks, I care more about performance:)";)...so my priority is to avoid memory leaks and then I optimize my code.
ok for me then :cool:
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]