|
Maximilien wrote: (just too lazy to create an account on sourceforge to ask in their forum)
Understood, but the probability of finding a CppCheck user on SourceForge's site is much greater than finding one on CodeProject's site. Don't you agree?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
yeah...
( i hate the voice of reason! )
Watched code never compiles.
|
|
|
|
|
Hai,
I have an exe in C++ which is connected to a Trade server and doing some operations based on the server.If the connection to this server is lost it should automatically reconnect.Is there Any solution for this
|
|
|
|
|
ShibuKizhepat wrote: Is there Any solution for this
Yes, client reconnects when it detects that the connection was interrupted. What have you tried so far and where have you been stuck?
ShibuKizhepat wrote: have an exe in C++
If this isn't your software then there is no solution "from the outside", but you can always contact the author and describe your scenario.
|
|
|
|
|
VC reporting some memory leaks in my application but without line number and file name. because of that i can't locate the leak.
Report is given below
Detected memory leaks!
Dumping objects ->
{159399} normal block at 0x04D98460, 1024 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{159398} normal block at 0x044E4F30, 36 bytes long.
Data: <HG ` ` > 48 47 97 01 A2 CD CD CD 60 84 D9 04 60 84 D9 04
{159397} normal block at 0x04D98028, 1024 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{159396} normal block at 0x04CABF20, 68 bytes long.
Data: <(H ( ( > 28 48 97 01 A2 CD CD CD 28 80 D9 04 28 80 D9 04
{159393} normal block at 0x044F37F0, 36 bytes long.
Data: < 7O 8PN 7O > F0 37 4F 04 38 50 4E 04 F0 37 4F 04 CD CD CD CD
{159392} normal block at 0x044E5038, 36 bytes long.
{21242} normal block at 0x04507C18, 4 bytes long.
The program 'D:\Kty\Program\kty.exe' has exited with code 0 (0x0).
How can I locate leak?
|
|
|
|
|
First thing to do is to avoid manually managing memory - then you won't have so many options for leaking memory. Replace raw pointers with decent smart pointers or just use automatic objects where you can.
Secondly there are some biggish blocks in there. Have a look in you code for anywhere you use big buffers that you dynamically allocate. As the blocks are only 1k in size just throw them on the stack.
After that if you're still having problems start thinking about using a diagnostic new and delete so you can start getting a handle on what you're allocating and not freeing.
Cheers,
Ash
|
|
|
|
|
thanks for reply.
After that if you're still having problems start thinking about using a diagnostic new and delete so you can start getting a handle on what you're allocating and not freeing
"diagnostic new and delete" - Can u explain it in detail
|
|
|
|
|
There are some other hints in there as well. The compiler makes sure allocated memory is filled with the value 0xCD for debug builds. That way the debugger can warn the user if you're trying to read uninitialized data.
As you can see, both leaks of size 1024, seem to be unused. Also 1024 is a neat number, and I bet you could just search in your source code for '1024'. Someone is probably allocating a buffer they think is big enough for a task.
You can also see the 'CD' pattern in the other dumps, indicating how the original layout might be. Assuming you have not altered the packing, it looks like the first 36 byte leak comes from a class or struct. The reason being the 3 CD in the middle. The struct might look something like
struct (or class)
{
int n;
char c;
...
}; where the n is 26691400 in this case. Does that number fit in somewhere? Like a database table index or similar?
There are a lot of hints if you know how to read and interpret them.
|
|
|
|
|
|
see _crtBreakAlloc[^]
basically, add this line to the very start of your program:
_crtBreakAlloc(159399);
then, when the CRT does its 159399th allocation, it will break (like an assert) and you can look at the stack to see who requested the allocation.
|
|
|
|
|
#define new DEBUG_NEW
add this line to the beginning of source files witch you suspect leaking memory.
then the report will have file name and line numbers.
(sorry for my poor english.)
|
|
|
|
|
Hi!
I've declared a global structure. Inside the constructor, I've initialized the structure elements. But I got the following error:
Error 2 error C2758: 'CInitMenu::initMnuContext' : must be initialized in constructor base/member initializer list e:\CricketProject\Cricket\InitMenu.cpp 51
Here is my structure:
struct SAppContext
{
irr::IrrlichtDevice *device;
irr::s32 counter;
irr::gui::IGUIButton* m_pPlayButton,*m_pOptionsButton,*m_pCreditsButton,*m_pExitButton;
};
I've created a reference to this structure in side my class:
private:
SAppContext &initMnuContext;
irr::IrrlichtDevice *dev;
irr::gui::IGUIButton *m_pPlayButton,*m_pOptionsButton,*m_pCreditsButton,*m_pExitButton;
I'm assigning my class members to this structure elements like this:
CInitMenu::CInitMenu(irr::IrrlichtDevice* device)
{
dev = device;
gui::IGUIButton* m_pPlayButton = device->getGUIEnvironment()->addButton(core::recti(x,y,x+width,y+height),0,PLAY_BUTTON,L"Play");
gui::IGUIButton* m_pOptionsButton = device->getGUIEnvironment()->addButton(core::recti(x,y,x+width,y+height),0,OPTIONS_BUTTON,L"Options");
gui::IGUIButton* m_pCreditsButton = device->getGUIEnvironment()->addButton(core::recti(x,y,x+width,y+height),0,CREDITS_BUTTON,L"Credits");
gui::IGUIButton* m_pExitButton = device->getGUIEnvironment()->addButton(core::recti(x,y,x+width,y+height),0,EXIT_BUTTON,L"Exit");
initMnuContext.device = device;
initMnuContext.m_pPlayButton = m_pPlayButton;
initMnuContext.m_pOptionsButton = m_pOptionsButton;
initMnuContext.m_pCreditsButton = m_pCreditsButton;
initMnuContext.m_pExitButton = m_pExitButton;
What modifications has to be done to get code work?
|
|
|
|
|
You have declared the initMnuContext as a reference:
SAppContext &initMnuContext;
But you are using it as if it is not a reference! Simply remove the ampersand in the declaration:
SAppContext initMnuContext;
|
|
|
|
|
|
Hi All ,
I have a code :
int CExWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if(CWnd::OnCreate(lpCreateStruct)==-1) return -1;
CClientDC dc(this);
pDC.CreateCompatibleDC(&dc);
bitmap.CreateCompatibleBitmap(&dc,Width,Height);
pDC.SelectObject(&bitmap);
return 0;
}
void CExWnd::OnPaint()
{
CClientDC dc(this);
Draw ( pDC ) ;
dc.BitBlt(0,0,Width,Height,&pDC,0,0,SRCCOPY);
}
This is a example . I have a question . Why WM_PAINT auto update when compatible with pDC . ( the same CClientDC ) .
I'm not good at English . Sorry !!
Thanks .
|
|
|
|
|
The underlying DC in your CClientDC is where the drawing gets visible. You can use temporary DC's to do painting, but then you will have to transfer it to the 'visual' DC. That's what the BitBlt call is doing.
|
|
|
|
|
Can you share for me documentary about it ?
Thanks .
|
|
|
|
|
You can start by reading about device contexts here[^]
|
|
|
|
|
I read but i don't understand what you say . .
I will try .
Thanks .
|
|
|
|
|
It is indeed really weird.
It looks like CClientDC directly or indirectly causes window to redraw in turn causing constant flow of WM_PAINT messages.
Even wierder, you can remove BitBlt from OnPaint and window will still redraw, providing your code is equivalent to mine.
This is a toughest question I have ever encountered on many discussion forums.
I have quickly tested your code on Vista and so far I did not find any answers.
I am looking into it and when (if) I find and answer it will be a real satisfaction.
Later, I am also going to test it on XP and Windows 7.
JohnCz
MS C++ MVP
|
|
|
|
|
Hi all.
How can i get a count of the characters present in a CString.
i.e For ex: CString str = Sample("10,20,30,40,50");
I want to get the "," character count i.e 5
Any idea
Thanks
Raj
|
|
|
|
|
You can use function strtok .
Have fun .
|
|
|
|
|
What's about this:
int GetCommaCount(const CString &str)
{
int count = 0;
for(int pos = 0; pos < str.GetLength(); pos++)
{
if (str[pos] == _T(','))
count++;
}
return count;
}
|
|
|
|
|
If you use the CStringT class you can do it via the SpanIncluding()[^] method.
It's time for a new signature.
|
|
|
|
|
It's not so true because, as the MSDN documentation says, SpanIncluding returns an empty substring if the first character in the string is not in the specified set.
|
|
|
|