Solved

VritualFree() does trouble !!

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

762 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

22 Experts available now in Live!

Get 1:1 Help Now