Solved

VritualFree() does trouble !!

Posted on 2000-04-14
3
482 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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