Solved

VritualFree() does trouble !!

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA Import all database objects 12 51
link access with Quickbooks 9 49
Apparent collision of square brackets in jQuery and Classic ASP 12 29
windbg taking it's time 32 91
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

809 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