Click here to Skip to main content
15,917,608 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: GDI+ Double Buffer and Flood Fill Pin
PJ Arends21-Oct-03 6:52
professionalPJ Arends21-Oct-03 6:52 
Generalsdi + CFormView help Pin
zhangmi-boymaxzm20-Oct-03 16:28
zhangmi-boymaxzm20-Oct-03 16:28 
GeneralAutomating the Insertion of C++ Code Pin
Jeff Miles20-Oct-03 16:03
Jeff Miles20-Oct-03 16:03 
GeneralRe: Automating the Insertion of C++ Code Pin
Christian Graus20-Oct-03 16:37
protectorChristian Graus20-Oct-03 16:37 
QuestionMaking text go to Ms Word file? Pin
DanYELL20-Oct-03 14:51
DanYELL20-Oct-03 14:51 
AnswerRe: Making text go to Ms Word file? Pin
Michael Dunn20-Oct-03 19:46
sitebuilderMichael Dunn20-Oct-03 19:46 
AnswerRe: Making text go to Ms Word file? Pin
Anonymous20-Oct-03 22:16
Anonymous20-Oct-03 22:16 
GeneralMemory allocations slow when launched from the debugger Pin
Wasteland720-Oct-03 14:50
Wasteland720-Oct-03 14:50 
To make this short, we're using the latest Visual Studio (.NET 2003) on Windows XP, and memory allocations are incredibly slower (takes about 12 times as long) when the executable is launched from within the debugger as compared to launched from a command line.

Specifically, I've got an example program that demonstrates this up at http://www.horningabout.com/temp/SpeedTest/ , if you want to take a look. It's just doing a loop and repeatedly allocating and freeing memory. VTune reports all of the time is being spent in RtlCompareMemoryUlong and RtlFillMemoryUlong when launched from within the debugger, while these are never called when launched from the command line. I have determined that these calls are in no way required to debug, since I can launch the program from a command line, then attach with a debugger, and then have the program continue, and it will be fast, not calling these functions.

After talking back and forth with one of the engineers on the VS team at MS, I found out that when NT creates a new process and initializes the heap, it sets some flags saying to clear the memory before allocating and after freeing it, which is what is taking all of the time. The code below is a quick workaround for anyone else experiencing this problem (note that it depends on some internal structures of the heap that I have only verified on XP):

int WasLaunchedInNTDebugger(void) {
	long *data;
	int ret=0;
	// When some debug flags are set on the heap, NT clears
	// the allocated memory with 0xbaadf00d, so we check
	// this to see if we were launched in a debugger
	data = HeapAlloc(GetProcessHeap(), 0, 8);
	if (*data == 0xbaadf00d) {
		ret=1;
	}
	HeapFree(GetProcessHeap(), 0, data);
	return ret;

}

void disableRtlHeapChecking(HANDLE heap) {
	extern HANDLE _crtheap;
	// This is dependent on the current implementation
	// of the XP (and 2K and NT?) heap which stores a
	// number of flags 16 bytes into the heap, and
	// checks the bitmask 0x7D030F60 when deciding
	// whether or not to clear the memory with 0xbaadf00d,
	// so, we're clearing all of the bits that may cause
	// the clearing to happen
	if (heap == NULL)
		heap = _crtheap;
	if (WasLaunchedInNTDebugger()) {
		// This assert is basically because these 2
		// values are the only valuse I saw, if there
		// are any values for these flags, they might
		// mean something special (or a different OS)
		// and we should take a closer look to see if
		// we're clearing anything important. 
		assert(*((long*)heap + 4) == 0x40000061 ||
			*((long*)heap + 4) == 0x40000060);
		// Clear the bad bits!
		*((long*)heap + 4) &= ~0x7D030F60;
	}
}


I hope this helps someone, it was a pain to figure out and fix!
GeneralHelp with Dialog in Doc/View Application Pin
jasonmgeorge20-Oct-03 12:54
jasonmgeorge20-Oct-03 12:54 
GeneralRe: Help with Dialog in Doc/View Application Pin
Anthony_Yio20-Oct-03 15:27
Anthony_Yio20-Oct-03 15:27 
GeneralRe: Help with Dialog in Doc/View Application Pin
Atif Mushtaq21-Oct-03 23:54
Atif Mushtaq21-Oct-03 23:54 
GeneralRegular Dll with dialog box Pin
ahmadnoori20-Oct-03 11:05
ahmadnoori20-Oct-03 11:05 
GeneralRe: Regular Dll with dialog box Pin
igor196020-Oct-03 11:38
igor196020-Oct-03 11:38 
GeneralRe: Regular Dll with dialog box Pin
ahmadnoori20-Oct-03 13:15
ahmadnoori20-Oct-03 13:15 
QuestionCreateFile and LockFile in atomic operation? Pin
Joe Woodbury20-Oct-03 10:44
professionalJoe Woodbury20-Oct-03 10:44 
AnswerRe: CreateFile and LockFile in atomic operation? Pin
John M. Drescher20-Oct-03 11:05
John M. Drescher20-Oct-03 11:05 
AnswerRe: CreateFile and LockFile in atomic operation? Pin
Neville Franks21-Oct-03 10:12
Neville Franks21-Oct-03 10:12 
GeneralRe: CreateFile and LockFile in atomic operation? Pin
Joe Woodbury21-Oct-03 10:57
professionalJoe Woodbury21-Oct-03 10:57 
GeneralRe: CreateFile and LockFile in atomic operation? Pin
Neville Franks21-Oct-03 11:08
Neville Franks21-Oct-03 11:08 
GeneralRe: CreateFile and LockFile in atomic operation? Pin
Joe Woodbury21-Oct-03 13:18
professionalJoe Woodbury21-Oct-03 13:18 
GeneralGet Pin
Anonymous20-Oct-03 9:16
Anonymous20-Oct-03 9:16 
GeneralRe: Get Pin
Joe Woodbury20-Oct-03 9:42
professionalJoe Woodbury20-Oct-03 9:42 
GeneralRe: Get Pin
David Crow20-Oct-03 10:09
David Crow20-Oct-03 10:09 
GeneralAbout burning libraries... Pin
Rafael Fernández López20-Oct-03 8:23
Rafael Fernández López20-Oct-03 8:23 
GeneralRe: About burning libraries... Pin
Joe Woodbury20-Oct-03 9:45
professionalJoe Woodbury20-Oct-03 9:45 

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.