Click here to Skip to main content
15,921,840 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: 64-bit strange issue, SetupDiEnumDeviceInfo Pin
CPallini23-May-11 4:12
mveCPallini23-May-11 4:12 
GeneralRe: 64-bit strange issue, SetupDiEnumDeviceInfo Pin
Maxwell Chen23-May-11 4:29
Maxwell Chen23-May-11 4:29 
QuestionRe: 64-bit strange issue, SetupDiEnumDeviceInfo Pin
CPallini23-May-11 4:32
mveCPallini23-May-11 4:32 
AnswerRe: 64-bit strange issue, SetupDiEnumDeviceInfo Pin
Maxwell Chen23-May-11 4:47
Maxwell Chen23-May-11 4:47 
GeneralRe: 64-bit strange issue, SetupDiEnumDeviceInfo Pin
CPallini23-May-11 6:03
mveCPallini23-May-11 6:03 
GeneralRe: 64-bit strange issue, SetupDiEnumDeviceInfo Pin
Maxwell Chen23-May-11 6:07
Maxwell Chen23-May-11 6:07 
GeneralRe: 64-bit strange issue, SetupDiEnumDeviceInfo Pin
Maxwell Chen25-May-11 1:33
Maxwell Chen25-May-11 1:33 
AnswerRe: 64-bit strange issue, SetupDiEnumDeviceInfo [Resolved] Pin
Maxwell Chen25-May-11 1:31
Maxwell Chen25-May-11 1:31 
Sam Varshavchik replied me in the "C++ professionals group" forum on LinkedIn. Based on his information, I resolved this issue.

The below was his comment.
Modern CPUs have no "memory alignment" issues. In the worst case scenario, the CPU will burn a few extra cycles fetching an adjacent memory word, to execute the instruction or fetch the data. No impact on the application, except for it taking a few ticks of the clock to complete.

Memory alignment issues were often an issue with older CPUs, such as the earlier versions of the Motorola 68K CPU family, where attempting to fetch a word at an odd address caused a trap. Modern CPUs just deal with this by burning more fuel, no harm done. Whatever your problem really is, a "memory alignment" issue would be on the bottom of my list of suspects.

The symptoms being described -- adding a debug statement making an apparent error go away -- often happen as a result of subtle memory corruption; such as wild pointer dereferencing, using memory after it's been freed, etc... Adding some debug statements does not really fix anything, it merely masks the bug. Many times, effects of memory corruption are very sensitive to the layout and the internal arrangement of the code in the final executable. Often, one might think that adding an innocuous debug statement magically fixes their problem, only to see things come crashing down hard, after making some other innocent change to some completely unrelated part of the same application.

There is no universal answer how to fix this, or where the problem is. Roll up your sleeves, it's old-fashioned debug time.

I often found a lot of value in a memory instrumentation and usage checker. For MS-Windows, your apparent platform, Purify is a popular tool for pin-pointing where things go astray. On Linux, I find valgrind to be indispensable, and worth every penny of its no-cost. Very often it began screaming at me about bugs in my code that I didn't even know about, yet!

Of course instrumenting code changes its runtime behavior, and might also have unpredictable results that depend on the timing of its execution -- especially with multithreaded applications. Can't win them all. 


I do not have the IBM Rational Purify tool (IBM asked me to register a user account), but I downloaded and installed the 30-day trial version of Intel Parallel Inspector 2011. It reported about 30 memory errors: most of them were in the built-in source code of Visual C++ 2010, but one occurrence was in my project source code. I looked some lines back before this line, initialized a DWORD variable with value 0 (the DWORD dwFilter in the code snippet below), and this issue is resolved.

The below is the related code snippet.
bool SetupDi::GetClassDevs(SetupDi::DeviceClass DevClass, PCTSTR sEnumerator,
		bool bAllClasses, bool bPresent, bool bProfile,
		bool bDefault, bool bInterface)
{
	const GUID* pGuid = NULL;
	switch(DevClass)
	{
	case eDC_System:
		pGuid = &GUID_DEVCLASS_SYSTEM;
		break;
	default:
		break;
	}

	DWORD dwFilter = 0;  // This line caused x64 release-build to fail.
	if(bAllClasses) {
		dwFilter |= DIGCF_ALLCLASSES;
	}
	if(bPresent) {
		dwFilter |= DIGCF_PRESENT;
	}
	if(bProfile) {
		dwFilter |= DIGCF_PROFILE;
	}
	if(bInterface) {
		dwFilter |= DIGCF_DEVICEINTERFACE;
	}
	if(bDefault && bInterface) {
		dwFilter |= DIGCF_DEFAULT;
	}

	m_hDevInfo = SetupDiGetClassDevs(pGuid, sEnumerator, NULL, dwFilter);
	if(!m_hDevInfo) {
		TRACE(_T("SetupDi::GetClassDevs, SetupDiGetClassDevs failed (0x%08X). \n"), GetLastError());
	}
	return (NULL != m_hDevInfo);
}

  Maxwell Chen

GeneralRe: 64-bit strange issue, SetupDiEnumDeviceInfo [Resolved] Pin
CPallini25-May-11 1:45
mveCPallini25-May-11 1:45 
QuestionNetServerEnum Function in Windows 2008 domains Pin
CADITC_CODER22-May-11 14:21
CADITC_CODER22-May-11 14:21 
AnswerRe: NetServerEnum Function in Windows 2008 domains Pin
barneyman22-May-11 19:05
barneyman22-May-11 19:05 
QuestionMake client area of dialog transparent, so i can see what is behind the window Pin
manchukuo22-May-11 10:20
manchukuo22-May-11 10:20 
AnswerRe: Make client area of dialog transparent, so i can see what is behind the window Pin
Albert Holguin22-May-11 11:02
professionalAlbert Holguin22-May-11 11:02 
GeneralRe: Make client area of dialog transparent, so i can see what is behind the window Pin
manchukuo22-May-11 11:33
manchukuo22-May-11 11:33 
GeneralRe: Make client area of dialog transparent, so i can see what is behind the window Pin
Albert Holguin22-May-11 11:45
professionalAlbert Holguin22-May-11 11:45 
AnswerRe: Make client area of dialog transparent, so i can see what is behind the window Pin
Mark Salsbery22-May-11 12:48
Mark Salsbery22-May-11 12:48 
AnswerRe: Make client area of dialog transparent, so i can see what is behind the window Pin
abhishek.biradar22-May-11 21:53
abhishek.biradar22-May-11 21:53 
AnswerRe: Make client area of dialog transparent, so i can see what is behind the window Pin
Iain Clarke, Warrior Programmer23-May-11 7:00
Iain Clarke, Warrior Programmer23-May-11 7:00 
GeneralRe: Make client area of dialog transparent, so i can see what is behind the window Pin
manchukuo23-May-11 7:11
manchukuo23-May-11 7:11 
GeneralRe: Make client area of dialog transparent, so i can see what is behind the window Pin
Iain Clarke, Warrior Programmer23-May-11 8:02
Iain Clarke, Warrior Programmer23-May-11 8:02 
QuestionKERNELBASE Exception Pin
Joschwenk66622-May-11 9:20
Joschwenk66622-May-11 9:20 
QuestionC++ variable arguments Pin
Sintax122-May-11 5:50
Sintax122-May-11 5:50 
AnswerRe: C++ variable arguments Pin
Luc Pattyn22-May-11 6:02
sitebuilderLuc Pattyn22-May-11 6:02 
GeneralRe: C++ variable arguments Pin
Sintax122-May-11 7:10
Sintax122-May-11 7:10 
GeneralRe: C++ variable arguments Pin
Luc Pattyn22-May-11 7:31
sitebuilderLuc Pattyn22-May-11 7:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.