Solved

VritualFree() does trouble !!

Posted on 2000-04-14
3
452 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now