|
When is the flickering occuring?
Steve
|
|
|
|
|
Flicker occurs when there are intermediate pixels on the screen. Example: draw a blue,filled rectangle, then draw a non-rectangle bitmap over that. The blue pixels 'under' the bitmap cause the effect. There are 2 solutions: 1) avoid the drawing of unneeded pixels by making your algorithm better (and faster) or using regions (see winapi documentation), 2) draw everything in a buffer (memory DC) and transfer that to the screen. This is called 'double buffering'.
The first solution is most of the times too difficult to implement, so solution 2 is widely used, although it is actually slower.
|
|
|
|
|
Hello all
Good day . Though this question is not relevant to MFC or Win32 but to do with VB generic behavior =>
I have a outlook plugin ( COM plugin ) developed in VB 6.0 . We have an external application which uses the outlook addin to get the contact details from outlook. The problem is here =>
We create a new application object and free it as below =>
Set gApp = New Outlook.Application
....
Set gApp = Nothing
After this code is executed when we click on outlook application it says "Operation failed" . It looks like the outlook application object is not well freed by the statement Set gApp = Nothing . But I checked by adding the line below to ensure if the gApp is really free or not .
If gApp is Nothing
Then Log("gApp is free")
Else
Log ( "gApp is not free")
Endif
Even after this check it shows gApp is free which does not seem to be the case .
What can I further do to make sure the object is really made NULL !!!!
Going crazy with VB
regards
redindian
|
|
|
|
|
dharani wrote: Going crazy with VB
Then please post your question in the correct forum! This has nothing to do with C/C++/MFC.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
dealing with outlook is especially difficult.
first you need to attempt to connect to running instance and if successfull set a flag.
if not current instance create one.
do your stuff.
then if you connected to running instance just free your stuff and go bye bye.
if you created an instance call close on it and then go bye bye.
NEVER call close on an instance you didnt create.
|
|
|
|
|
Roger Broomfield wrote: dealing with outlook is especially difficult.
I have not found this either in C++ or C#, the latter being especially easy.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
What I found, was that Outlook 2007, was unfriendly. It is a single instance multi process application that needs to be specifically closed. If you start it, you close it, if you dont specifically close an instance you started it sits in running processes until you log off. If you dont start it, you dont close it, but you do release all instances of objects you created. Maybe this is because I dont have the latest VS. But I dont see how that would affect the Outlook object model.
|
|
|
|
|
I use the
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
to check the memory leak, but it output a lot of non-useful info, Is there good way to check where the memory leak?
|
|
|
|
|
normally when u create project in Visual studio ,and after debugging it (ofcourse in debug mode) , when u close the app, Visual studio will shows any unfreezed memory in the output window( ALT+CTRL+ O).
sometimes this information is sufficient to detect the memory leak(depends on codes and the persons knowledge)
if u r trying to find memory leak and vs's output is not sufficient try using boundsckecer or similar softwares ( http://en.wikipedia.org/wiki/BoundsChecker) . Boundschecker is not free.
visual leak detector is a free one(http://www.codeproject.com/KB/applications/visualleakdetector.aspx)
hopes this helps.
If u can Dream... U can do it
|
|
|
|
|
HI
This macro can only report the memory leak that has been made by new.
www.logicsims.ir
|
|
|
|
|
Assuming you have no calls to calloc and malloc, ...
http://stackoverflow.com/questions/3509214/overloading-new-and-delete-in-c
An exception could be the source of the problem since class destructors are not called if an exception is encountered and not handled.
|
|
|
|
|
I'm partial to GlowCode[^]. If you have a few hundred dollars to invest, I'd recommend it.
L u n a t i c F r i n g e
|
|
|
|
|
Thanks for all your reply.
Happy new year.
|
|
|
|
|
Generally I prefer UMDH. Its free from microsoft and works great.
We can customize memory leak detections to some UI operations, a DLL.
|
|
|
|
|
How to let the code be more elegant? Just too much delete .
BTW, while not to deal the exception in side the function, try catch finally can't be used.
void f()
{
char * buf = new char[128];
...
if (...)
{
delete []buf;
throw runtime_error("...");
}
...
if (...)
{
delete []buf;
throw runtime_error("...");
}
}
=====================
I think what I need is something like constructor and destructor, but for a function.
By overriding operator() of a class may solve some problem, but the function it hard to be re-entrantable, and other misc problems.
Most of the cases the function should be short, so this couldn't be a problem, but in some rare case, it has to deal a lot of data,
and the function looks very long.
modified on Friday, December 24, 2010 3:38 AM
|
|
|
|
|
The try-catch block is the most elegant solution, why cannot you use it?
Alternatives are the C -like goto and the if chain you depicted.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I think exception is rarely happened, I want to catch it in the more outside fucntion, like main .
|
|
|
|
|
If you want to catch it in the main block, then why don't you just throw it?
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
How about this?
struct Exception
{
char *text;
void *data;
}
enum ERROR{NONE,...};
void f()
{
char * buf = new char[128];
ERROR e = NONE;
...
if (...) e = ...
if (...) e = ...
if (...) e = ...
if(NONE != e)
{
Exception exp;
exp.text = FindTextForError(e);
exp.data = buf;
throw exp;
}
}
caller()
{
try
{
f()
}
catch(Exception exp)
{
delete exp.data;
}
}
|
|
|
|
|
what abt using smarpointers(ref counting) ?
If u can Dream... U can do it
|
|
|
|
|
Yes, it is fine.
But when I manapulate a dababase instead of memory,
for example, a prepared statement, I need to close it before leave.
Hope it can be common.
|
|
|
|
|
Just define your statement as a class,
that will perform all needed clearances and closing in its destructor.
Then - declare an instance (not an allocation by new) of the class object
in the throwing function -
the destructor will be called in any case (for all on-stack-instances)
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
|
|
|
|
|
A class is ok in the case.
But in another case, the life scope of the object of the class
may larger than the try..catch... block, this can
bring problems, just because the scopes are not inconsistent.
However, there seems no proper way which is also efficient.
BTW, is there any language that can provide some thing like
constructor and distructor for a function?
|
|
|
|
|
All of the variables local defined in a function,
will be constructed on the stack at the beginning of the function
and then destructed - at the end of the function (even there was a throwing)
So you could provide a class for a function service, for example:
class CDBStatement;
class CDBStatementService
{
bool m_bOwner;
CDBStatement* m_pcStatement;
public:
CDBStatementService(CDBStatement* pcStatement, bool bOwner)
: m_pcStatement(pcStatement), m_bOwner(bOwner) {};
~CDBStatementService() {
if (m_pcStatement) {
m_pcStatement->Close();
if (m_bOwner) {
delete m_pcStatement;
}
}
}
};
void TestThrowing()
{
CDBStatementService cDBStatementService(new CDBStatement(), true);
}
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
|
|
|
|
|
you said u need to close the database before u leave right ? so leave means , when the scope of that object goes away right ? so it must be possible to implement via const/dest . say for example when ur function first called the const of the object(declared inside the function) executes and when ur function terminates , the dest of the object executes. u can safely put things there right ?
If u can Dream... U can do it
|
|
|
|