Click here to Skip to main content
15,922,427 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: pfmon.exe tool Pin
George_George20-Jan-08 16:22
George_George20-Jan-08 16:22 
GeneralCreateProcessAsUser Pin
dilip.kamalia17-Jan-08 3:33
dilip.kamalia17-Jan-08 3:33 
QuestionRe: CreateProcessAsUser Pin
Mark Salsbery17-Jan-08 7:34
Mark Salsbery17-Jan-08 7:34 
GeneralRe: CreateProcessAsUser Pin
dilip.kamalia17-Jan-08 18:56
dilip.kamalia17-Jan-08 18:56 
GeneralRe: CreateProcessAsUser Pin
Mark Salsbery18-Jan-08 8:01
Mark Salsbery18-Jan-08 8:01 
Generalchanging background color DFC_CAPTION, DFCS_CAPTIONCLOSE Pin
hari prasad sathpadi17-Jan-08 3:24
hari prasad sathpadi17-Jan-08 3:24 
GeneralRe: changing background color DFC_CAPTION, DFCS_CAPTIONCLOSE Pin
James R. Twine17-Jan-08 4:18
James R. Twine17-Jan-08 4:18 
Generalmy code to prove working set larger than virtual bytes Pin
George_George17-Jan-08 3:22
George_George17-Jan-08 3:22 
Hello everyone,


From the definition of working set, it is a subset of virtual pages resident in physical memory -- from book Windows Internals. It means working set could not be larger than virtual memory (subset relationship).

But the following simple code on Windows Server 2003 proves (if you monitor virtual bytes counter and working set bytes conuter from perfmon), if we do not unmap the page map file, the working set will continue to increase (and much larger than virtual bytes) until we unmap it.

Take a breakpoint before following code section,

// close mapped files to avoid leak
for (sectionIndex = 0; sectionIndex < size/allocSize; sectionIndex++)
{
    if (map [sectionIndex])
    {
        UnmapViewOfFile(map [sectionIndex]);
    }
}


Any ideas? Does my code break the definition of working set? Why working set is much larger than virtual bytes?

int main(int argc, char* argv[]) 
{ 
	LARGE_INTEGER start,end; 
	LARGE_INTEGER freq; 
	QueryPerformanceCounter(&start); 
	QueryPerformanceFrequency(&freq); 
	MEMORYSTATUS memstat; 
	void** map;
	int sectionIndex = 0;
	memstat.dwLength = sizeof(memstat); 
	GlobalMemoryStatus(&memstat); 

	// basic file mapping test (512 MB) 
	long long size = 512*1024*1024; 

	HANDLE mapping = 
	CreateFileMapping(NULL,NULL,PAGE_READWRITE|SEC_COMMIT,(DWORD)(size << 32),DWORD(size),NULL); 
	if (mapping) 
	{ 
		// create and destroy temporary views 
		SYSTEM_INFO sysInfo; 
		GetSystemInfo(&sysInfo); 
		const int allocSize = sysInfo.dwAllocationGranularity; 

		GlobalMemoryStatus(&memstat); 

		void *mem = new char[allocSize]; 
		memset(mem,0x11,allocSize); 

		map = (void**) new char [sizeof(void*) * size / allocSize];

		for (int i=0; i < 10; i++) 
		{ 

			sectionIndex = 0;
			for (long long offset=0; offset<=size-allocSize; offset+=allocSize) 
			{ 
				map [sectionIndex] = 
				MapViewOfFile(mapping,FILE_MAP_WRITE,(DWORD)(offset<<32),(DWORD)offset,allocSize); 
				if (map [sectionIndex]) 
				{ 
					memcpy(map [sectionIndex],mem,allocSize); 
					// UnmapViewOfFile(map);
				}

				sectionIndex++;
			} // for (long long offset=0; offset<=size-allocSize; offset+=allocSize) 
			
			// close mapped files to avoid leak
			for (sectionIndex = 0; sectionIndex < size/allocSize; sectionIndex++)
			{
				if (map [sectionIndex])
				{ 
					UnmapViewOfFile(map [sectionIndex]);
				}
			}

			GlobalMemoryStatus(&memstat); 

			sectionIndex = 0;
			for (long long offset=0; offset <= size-allocSize; offset+=allocSize) 
			{ 
				map [sectionIndex] = 
				MapViewOfFile(mapping,FILE_MAP_READ,(DWORD)(offset << 32),(DWORD)offset,allocSize); 
				if (map [sectionIndex]) 
				{ 
					for (int t=0; t < allocSize; t++) 
					{ 
						if (((char *)(map [sectionIndex]))[t]!=0x11) 
						{ 
							OutputDebugString("Memory read failed\n"); 
						} 
					} 
				} 

				UnmapViewOfFile(map [sectionIndex]);
			} 

			// close mapped files to avoid leak
			/*
			for (sectionIndex = 0; sectionIndex < size/allocSize; sectionIndex++)
			{
				if (map [sectionIndex])
				{ 
					UnmapViewOfFile(map [sectionIndex]);
				}
			}
			*/

			GlobalMemoryStatus(&memstat); 
		} // for (int i=0; i < 10; i++)

		QueryPerformanceCounter(&end); 

		GlobalMemoryStatus(&memstat); 

		printf("Time %.3f\n", 
		double(end.QuadPart-start.QuadPart)/double(freq.QuadPart)); 
		CloseHandle(mapping); 
		delete[] mem; 
		GlobalMemoryStatus(&memstat); 
	} //if (mapping)

	return 0;
} 



thanks in advance,
George
GeneralDisplaying line numbers Pin
Sanjay K17-Jan-08 1:08
Sanjay K17-Jan-08 1:08 
GeneralRe: Displaying line numbers Pin
Iain Clarke, Warrior Programmer17-Jan-08 2:04
Iain Clarke, Warrior Programmer17-Jan-08 2:04 
QuestionRe: Displaying line numbers Pin
David Crow17-Jan-08 2:29
David Crow17-Jan-08 2:29 
GeneralRe: Displaying line numbers Pin
Hamid_RT17-Jan-08 18:08
Hamid_RT17-Jan-08 18:08 
QuestionHow to use libwww Pin
ktm TechMan17-Jan-08 0:35
ktm TechMan17-Jan-08 0:35 
GeneralError handling - a best way Pin
CodingLover16-Jan-08 22:23
CodingLover16-Jan-08 22:23 
GeneralRe: Error handling - a best way Pin
CPallini16-Jan-08 23:21
mveCPallini16-Jan-08 23:21 
GeneralRe: Error handling - a best way Pin
CodingLover16-Jan-08 23:38
CodingLover16-Jan-08 23:38 
GeneralRe: Error handling - a best way Pin
CPallini17-Jan-08 0:22
mveCPallini17-Jan-08 0:22 
GeneralRe: Error handling - a best way Pin
CodingLover17-Jan-08 0:42
CodingLover17-Jan-08 0:42 
QuestionRe: Error handling - a best way Pin
David Crow17-Jan-08 2:31
David Crow17-Jan-08 2:31 
GeneralRe: Error handling - a best way Pin
CPallini17-Jan-08 3:32
mveCPallini17-Jan-08 3:32 
GeneralRe: Error handling - a best way Pin
Nishad S16-Jan-08 23:56
Nishad S16-Jan-08 23:56 
GeneralRe: Error handling - a best way Pin
CodingLover17-Jan-08 0:33
CodingLover17-Jan-08 0:33 
GeneralRe: Error handling - a best way Pin
Nishad S17-Jan-08 0:53
Nishad S17-Jan-08 0:53 
GeneralRe: Error handling - a best way Pin
James R. Twine17-Jan-08 4:11
James R. Twine17-Jan-08 4:11 
GeneralRe: Error handling - a best way Pin
CodingLover17-Jan-08 15:09
CodingLover17-Jan-08 15:09 

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.