please dont rip this site Prev Next

VirtualFreeEx info  Overview  Group

The VirtualFreeEx function releases, decommits, or both, a region of memory within the virtual address space of a specified process.

The difference between the VirtualFreeEx function and the VirtualFree function is that VirtualFree frees memory within the address space of the calling process, while VirtualFreeEx lets you specify a process.

BOOL VirtualFreeEx(

    HANDLE hProcess,

// process within which to free memory

    LPVOID lpAddress,

// starting address of memory region to free

    DWORD dwSize,

// size, in bytes, of memory region to free

    DWORD dwFreeType 

// type of free operation

   );

Parameters

hProcess
Handle to a process. The function frees memory within the virtual address space of this process.

You must have PROCESS_VM_OPERATION access to this process. If you do not, the function fails.

lpAddress
Pointer to the starting address of the region of memory to free.

If the MEM_RELEASE flag is set in the dwFreeType parameter, lpAddress must be the base address returned by the VirtualAllocEx function when the region was reserved.

dwSize
Specifies the size, in bytes, of the region of memory to free.

If the MEM_RELEASE flag is set in the dwFreeType parameter, dwSize must be zero. The function frees the entire region that was reserved in the initial allocation call to VirtualAllocEx.

If the MEM_DECOMMIT flag is set, the function decommits all memory pages that contain one or more bytes in the range from the lpAddress parameter to (lpAddress+dwSize). This means, for example, that a 2-byte region of memory that straddles a page boundary causes both pages to be decommitted.

The function decommits the entire region that was reserved by VirtualAllocEx. If the following three conditions are met:

· the MEM_DECOMMIT flag is set

· lpAddress is the base address returned by the VirtualAllocEx function when the region was reserved

· dwSize is zero

The entire region the enters the reserved state.

dwFreeType
Set of bit flags that specifies the type of free operation. You must set one of the following two flags:

Flag

Meaning

MEM_DECOMMIT

The function decommits the specified region of pages. The pages enter the reserved state.

The function does not fail if you attempt to decommit an uncommitted page. This means that you can decommit a range of pages without first determining their current commitment state.

MEM_RELEASE

The function releases the specified region of pages. The pages enter the free state.

If you specify this flag, dwSize must be zero, and lpAddress must point to the base address returned by the VirtualAllocEx function when the region was reserved. The function fails if either of these conditions is not met.

If any pages in the region are currently committed, the function first decommits and then releases them.

The function does not fail if you attempt to release pages that are in different states, some reserved and some committed. This means that you can release a range of pages without first determining their current commitment state.

Return Values

If the function succeeds, the return value is a nonzero value.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Each page of memory in a process’s virtual address space is in one of three states:

State

Meaning

Free

The page is neither committed nor reserved. The page is not accessible to the process. Attempting to read from or write to a free page results in an access violation exception.

You can use the VirtualFreeEx function to put reserved or committed memory pages into the free state.

Reserved

The page is reserved. The range of addresses cannot be used by other allocation functions. The page is not accessible and has no physical storage associated with it. Attempting to read from or write to a free page results in an access violation exception.

You can use the VirtualFreeEx function to put committed memory pages into the reserved state, and to put reserved memory pages into the free state.

Committed

The page is committed. Physical storage in memory or in the paging file on disk is allocated for the page, and access is controlled by a protection code.

The operating system initializes and loads each committed page into physical memory only at the first attempt to read from or write to that page.

When a process terminates, the operating system releases all storage for committed pages.

You can use the VirtualAllocEx function to put committed memory pages into either the reserved or free state.

The VirtualFreeEx function can perform the following operations:

The VirtualFreeEx function can decommit a range of pages that are in different states, some committed and some uncommitted. This means that you can decommit a range of pages without first determining the current commitment state of each page. Decommitting a page releases its physical storage, either in memory or in the paging file on disk.

If a page is decommitted but not released, its state changes to reserved. You can subsequently call VirtualAllocEx to commit it, or VirtualFreeEx to release it. Attempting to read from or write to a reserved page results in an access violation exception.

The VirtualFreeEx function can release a range of pages that are in different states, some reserved and some committed. This means that you can release a range of pages without first determining the current commitment state of each page. The entire range of pages originally reserved by the VirtualAllocEx function must be released at the same time.

If a page is released, its state changes to free, and it is available for subsequent allocation operations. Attempting to read from or write to a free page results in an access violation exception.

See Also

GlobalAlloc, GlobalFree, VirtualAlloc, VirtualAllocEx, VirtualFree 


file: /Techref/os/win/api/win32/func/src/f90_11.htm, 10KB, , updated: 2000/4/7 11:19, local time: 2024/11/24 13:02,
TOP NEW HELP FIND: 
3.145.33.244:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://sxlist.com/TECHREF/os/win/api/win32/func/src/f90_11.htm"> VirtualFreeEx</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .