|
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.
|
|
|
|
|
Oops!
It's time for a new signature.
|
|
|
|
|
std::count_if is another method.
Something like
bool is_comma(char c)
{
return c == ',';
}
std::string s = "1,2,3,4";
int count = std::count_if(s.begin(), s.end(), is_comma);
Edit for clarification: This algorithm can of course be applied to a CString as well using the GetBuffer() member.
home
modified on Thursday, August 26, 2010 5:31 AM
|
|
|
|
|
Of course you don't need GetBuffer :
#include <algorithm>
using namespace std;
bool is_comma(TCHAR c)
{
return c==_T(',');
}
LPCTSTR beg = (LPCTSTR) str;
LPCTSTR end = beg + str.GetLength();
int result = count_if(beg, end, is_comma);
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]
|
|
|
|
|
|
Assuming your string is
CString str = _T("Sample(10,20,30,40,50)");
Then
int start = -1;
int count = 0;
while ( (start = str.Find(_T(','), start + 1)) != -1)
count++;
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]
|
|
|
|
|
raju_shiva wrote: i.e For ex: CString str = Sample("10,20,30,40,50");
I want to get the "," character count i.e 5
Shouldn't that be 4?
"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
|
|
|
|
|