Solved

VritualFree() does trouble !!

Posted on 2000-04-14
3
474 Views
Last Modified: 2013-12-03


Why does not VirtualFree() decommit pages ?


   hfile = CreateFileMapping( (HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE|SEC_RESERVE, 0, size, name );

   hmap = MapViewOfFile( hfile, FILE_MAP_ALL_ACCESS, 0, 0, 0 );


   for( )
   {
     halloc = VirtualAlloc( hmap, x_size, MEM_COMMIT, PAGE_READWRITE );
   
     // some stuff

     VirtualFree( halloc, x_size, MEM_DECOMMIT );
     // GetLastError() returns Error # 87
     // Error: Incorrect parameter
     // VirtualFree() does not decommit the pages commited by VirtualAlloc()

   }

   UnmapViewOfFile( hmap )
   CloseHandle( hfile )
0
Comment
Question by:mars
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
NickRepin earned 100 total points
ID: 2717633
<<The SEC_RESERVE flag is intended for file mappings that are backed by the paging file, and therefore use SEC_RESERVE only when hFile is -1. The pages are reserved just as they are when the MEM_RESERVE flag is used in VirtualAlloc(). The pages can be committed by subsequently using the VirtualAlloc() application programming interface (API), specifying MEM_COMMIT. Once committed, these pages cannot be decommitted.

>>
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2717636
0
 

Author Comment

by:mars
ID: 2718698
Thank you very much. Since Windows NT 3.5, the help file about CreateFileMapping is always not updated with such important note !!! I can't believe it.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question