Click here to Skip to main content
15,894,546 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: working set, virtual bytes and private bytes Pin
led mike11-Jan-08 9:17
led mike11-Jan-08 9:17 
GeneralRe: working set, virtual bytes and private bytes Pin
George_George12-Jan-08 4:10
George_George12-Jan-08 4:10 
GeneralRe: working set, virtual bytes and private bytes Pin
led mike15-Jan-08 6:13
led mike15-Jan-08 6:13 
GeneralRe: working set, virtual bytes and private bytes Pin
George_George15-Jan-08 6:23
George_George15-Jan-08 6:23 
GeneralRe: working set, virtual bytes and private bytes Pin
led mike15-Jan-08 7:50
led mike15-Jan-08 7:50 
GeneralRe: working set, virtual bytes and private bytes Pin
George_George15-Jan-08 19:17
George_George15-Jan-08 19:17 
GeneralRe: working set, virtual bytes and private bytes Pin
led mike16-Jan-08 5:04
led mike16-Jan-08 5:04 
GeneralRe: working set, virtual bytes and private bytes Pin
George_George16-Jan-08 19:31
George_George16-Jan-08 19:31 
Thanks led,


led mike wrote:
You can explore the working set list using the kernel debugger


My question is not and I am not interested to explorer the working set list. But wondering why working set could be larger than virtual bytes.

I have written a program to show my idea. I have tested it under Windows Server 2003. If you are interested, here I can share with you. You can monitor the working set counter and virtual bytes counter and you can find working set is much higher 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;
} 



regards,
George
GeneralRe: working set, virtual bytes and private bytes Pin
Hamid_RT9-Jan-08 18:21
Hamid_RT9-Jan-08 18:21 
GeneralRe: working set, virtual bytes and private bytes Pin
George_George9-Jan-08 18:30
George_George9-Jan-08 18:30 
GeneralRe: working set, virtual bytes and private bytes Pin
Hamid_RT9-Jan-08 19:12
Hamid_RT9-Jan-08 19:12 
GeneralRe: working set, virtual bytes and private bytes Pin
George_George9-Jan-08 19:22
George_George9-Jan-08 19:22 
GeneralRe: working set, virtual bytes and private bytes Pin
Hamid_RT9-Jan-08 19:39
Hamid_RT9-Jan-08 19:39 
GeneralRe: working set, virtual bytes and private bytes Pin
George_George9-Jan-08 20:23
George_George9-Jan-08 20:23 
Generalcapturing the value Pin
Chandrasekharan P9-Jan-08 0:00
Chandrasekharan P9-Jan-08 0:00 
GeneralRe: capturing the value Pin
Maxwell Chen9-Jan-08 0:04
Maxwell Chen9-Jan-08 0:04 
GeneralRe: capturing the value Pin
Chandrasekharan P9-Jan-08 0:07
Chandrasekharan P9-Jan-08 0:07 
GeneralRe: capturing the value Pin
Rajesh R Subramanian9-Jan-08 0:06
professionalRajesh R Subramanian9-Jan-08 0:06 
QuestionRe: capturing the value Pin
Hamid_RT9-Jan-08 0:42
Hamid_RT9-Jan-08 0:42 
GeneralRe: capturing the value Pin
Nishad S9-Jan-08 1:36
Nishad S9-Jan-08 1:36 
QuestionRe: capturing the value Pin
David Crow9-Jan-08 2:53
David Crow9-Jan-08 2:53 
GeneralRe: capturing the value Pin
Nishad S9-Jan-08 2:59
Nishad S9-Jan-08 2:59 
GeneralRe: capturing the value Pin
CPallini9-Jan-08 3:23
mveCPallini9-Jan-08 3:23 
GeneralRe: capturing the value Pin
Nishad S9-Jan-08 3:26
Nishad S9-Jan-08 3:26 
GeneralRe: capturing the value Pin
CPallini9-Jan-08 3:46
mveCPallini9-Jan-08 3:46 

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.