473,624 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

my code to prove working set larger than virtual bytes

200 New Member
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,

Expand|Select|Wrap|Line Numbers
  1.             // close mapped files to avoid leak
  2.             for (sectionIndex = 0; sectionIndex < size/allocSize; sectionIndex++)
  3.             {
  4.                 if (map [sectionIndex])
  5.                 { 
  6.                     UnmapViewOfFile(map [sectionIndex]);
  7.                 }
  8.             }
  9.  
Any ideas? Does my code break the definition of working set? Why working set is much larger than virtual bytes?

Expand|Select|Wrap|Line Numbers
  1. #include <windows.h> 
  2. #include <stdio.h> 
  3.  
  4. int main(int argc, char* argv[]) 
  5.     LARGE_INTEGER start,end; 
  6.     LARGE_INTEGER freq; 
  7.     QueryPerformanceCounter(&start); 
  8.     QueryPerformanceFrequency(&freq); 
  9.  
  10.     MEMORYSTATUS memstat; 
  11.     void** map;
  12.     int sectionIndex = 0;
  13.     memstat.dwLength = sizeof(memstat); 
  14.     GlobalMemoryStatus(&memstat); 
  15.  
  16.     // basic file mapping test (512 MB) 
  17.     long long size = 512*1024*1024; 
  18.  
  19.     HANDLE mapping = 
  20.     CreateFileMapping(NULL,NULL,PAGE_READWRITE|SEC_COMMIT,(DWORD)(size>>32),DWORD(size),NULL); 
  21.     if (mapping) 
  22.     { 
  23.         // create and destroy temporary views 
  24.         SYSTEM_INFO sysInfo; 
  25.         GetSystemInfo(&sysInfo); 
  26.         const int allocSize = sysInfo.dwAllocationGranularity; 
  27.  
  28.         GlobalMemoryStatus(&memstat); 
  29.  
  30.         void *mem = new char[allocSize]; 
  31.         memset(mem,0x11,allocSize); 
  32.  
  33.         map = (void**) new char [sizeof(void*) * size / allocSize];
  34.  
  35.         for (int i=0; i<10; i++) 
  36.         { 
  37.  
  38.             sectionIndex = 0;
  39.             for (long long offset=0; offset<=size-allocSize; offset+=allocSize) 
  40.             { 
  41.                 map [sectionIndex] = 
  42.                 MapViewOfFile(mapping,FILE_MAP_WRITE,(DWORD)(offset>>32),(DWORD)offset,allocSize); 
  43.                 if (map [sectionIndex]) 
  44.                 { 
  45.                     memcpy(map [sectionIndex],mem,allocSize); 
  46.                     // UnmapViewOfFile(map);
  47.                 }
  48.  
  49.                 sectionIndex++;
  50.             } // for (long long offset=0; offset<=size-allocSize; offset+=allocSize) 
  51.  
  52.             // close mapped files to avoid leak
  53.             for (sectionIndex = 0; sectionIndex < size/allocSize; sectionIndex++)
  54.             {
  55.                 if (map [sectionIndex])
  56.                 { 
  57.                     UnmapViewOfFile(map [sectionIndex]);
  58.                 }
  59.             }
  60.  
  61.             GlobalMemoryStatus(&memstat); 
  62.  
  63.             sectionIndex = 0;
  64.             for (long long offset=0; offset<=size-allocSize; offset+=allocSize) 
  65.             { 
  66.                 map [sectionIndex] = 
  67.                 MapViewOfFile(mapping,FILE_MAP_READ,(DWORD)(offset>>32),(DWORD)offset,allocSize); 
  68.                 if (map [sectionIndex]) 
  69.                 { 
  70.                     for (int t=0; t<allocSize; t++) 
  71.                     { 
  72.                         if (((char *)(map [sectionIndex]))[t]!=0x11) 
  73.                         { 
  74.                             OutputDebugString("Memory read failed\n"); 
  75.                         } 
  76.                     } 
  77.                 } 
  78.  
  79.                 UnmapViewOfFile(map [sectionIndex]);
  80.             } 
  81.  
  82.             // close mapped files to avoid leak
  83.             /*
  84.             for (sectionIndex = 0; sectionIndex < size/allocSize; sectionIndex++)
  85.             {
  86.                 if (map [sectionIndex])
  87.                 { 
  88.                     UnmapViewOfFile(map [sectionIndex]);
  89.                 }
  90.             }
  91.             */
  92.  
  93.             GlobalMemoryStatus(&memstat); 
  94.         } // for (int i=0; i<10; i++)
  95.  
  96.         QueryPerformanceCounter(&end); 
  97.  
  98.         GlobalMemoryStatus(&memstat); 
  99.  
  100.         printf("Time %.3f\n", 
  101.         double(end.QuadPart-start.QuadPart)/double(freq.QuadPart)); 
  102.         CloseHandle(mapping); 
  103.         delete[] mem; 
  104.         GlobalMemoryStatus(&memstat); 
  105.     } //if (mapping)
  106.  
  107.     return 0;
  108.  

thanks in advance,
George
Jan 17 '08 #1
0 1579

Sign in to post your reply or Sign up for a free account.

Similar topics

4
21609
by: Mike | last post by:
hopefully this is an easy one to solve and I'm just missing something little... basically, I had a nice little website running with php, apache, etc... that uses imagecreatefromjpeg to create thumbnails of larger pictures. recently, I upgraded my system from suse 8.2 to suse 9.0, so I assume my php/apache rpms were upgraded in the process...
2
3775
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to produce two messages having the same message digest. That conjecture is false, as demonstrated by Wang, Feng, Lai and Yu in 2004 . Just recently, Wang, Yu, and Lin showed a short- cut solution for finding collisions in SHA-1 . Their result
171
7687
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles) like it because you can split the code from the design. That is logical. But if you are the only one working on the code, it seem a little overkill. I use Dreamweaver to do my design and find it a bit of a hassle to have multiple files open...
5
1873
by: Steven T. Hatton | last post by:
I'm engaged in a discussion on the Qt mailing list regarding exceptions. It has been stated that exception handling leads to significantly larger executable images than does 'error-code' programming. Nobody has provided a concrete example of this, and I would like to know what the technical issues really are. Searching the Internet only resulted in finding more rumor and legend regarding this issue. What are the facts? -- NOUN:1....
1
1863
by: anonymous | last post by:
I have written a simple code using inline assembly to compare the individual bytes of two lists (X and Y) and to store the higher byte of each list in a third list (LARGER). The code is as follows (implemented on VC++ 2008 Express edition): #include <stdio.h> #include <malloc.h> int main() { char *X,*Y,*LARGER; int i; int N;
1
2221
by: George2 | last post by:
Hello everyone, I am using Windows Server 2003 Performance Counter tool to monitor the memory consumed by my process. The interested terms are working set, virtual bytes and private bytes. My questions are, 1. If I want to watch the real physical memory consumed by current process, which one should I monitor? 2. If I want to watch the physical memory + swap file consumed by current process, which one should I monitor? 3. Any more...
0
1306
by: George2 | last post by:
Hello everyone, I am using perfmon to watch the working set and virtual bytes, when I do a keyword search in SourceInsight. I found the value of working set is larger than virtual bytes when do a search, I am confused how could working set larger than virtual bytes? I have this confusion is virtual bytes is all things -- reserved, committed memory -- which includes RAM (working set) and page swap file. So, virtual bytes should be always...
0
1629
by: George2 | last post by:
Hello everyone, Sorry that this question is related to another question I posted some time before because I have some new findings and self-analysis. My question is why sometimes from perfmon on Windows, working set larger than virtual memory? I think virtual memory is the total size of memory (committed, reserved, shared, private) and working set is just the RAM touched by current process currently. Virtual memory should always larger...
1
2127
by: George2 | last post by:
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
0
8170
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8619
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8334
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.