1 VirtualFree Operate (Memoryapi.h)
Adam Collado edited this page 2025-10-27 12:12:27 +08:00


Releases, decommits, or releases and decommits a area of pages inside the digital deal with house of the calling process. To free memory allotted in another process by the VirtualAllocEx operate, use the VirtualFreeEx perform. A pointer to the base handle of the region of pages to be freed. Release, this parameter should be the base address returned by the VirtualAlloc function when the area of pages is reserved. The scale of the region of memory to be freed, in bytes. Launch, this parameter must be zero (zero). The operate frees the entire region that's reserved in the initial allocation call to VirtualAlloc. Dimension). This means, for instance, that a 2-byte area of memory that straddles a page boundary causes both pages to be decommitted. If lpAddress is the base handle returned by VirtualAlloc and dwSize is 0 (zero), the operate decommits your complete area that is allotted by VirtualAlloc.


After that, the complete region is within the reserved state. The type of free operation. This parameter should be certainly one of the next values. The perform does not fail when you attempt to decommit an uncommitted web page. This implies you could decommit a range of pages with out first determining the present commitment state. DECOMMIT value shouldn't be supported when the lpAddress parameter provides the base deal with for an enclave. That is true for enclaves that don't help dynamic memory management (i.e. SGX1). DECOMMIT anywhere in the enclave. In the event you specify this worth, dwSize should be 0 (zero), and lpAddress should point to the bottom address returned by the VirtualAlloc function when the area is reserved. The function fails if either of those situations is not met. If any pages within the region are dedicated presently, the function first decommits, and then releases them. The function does not fail should you try and release pages which can be in numerous states, some reserved and some committed.


This means you could launch a variety of pages with out first figuring out the current dedication state. Launch, this parameter can moreover specify one in all the following values. If the operate succeeds, the return worth is nonzero. If the function fails, the return worth is 0 (zero). To get extended error Memory Wave info, name GetLastError. Every page of memory in a course of virtual tackle space has a Web page State. The VirtualFree function can decommit a spread of pages which might be in several states, some dedicated and some uncommitted. This means that you would be able to decommit a range of pages with out first determining the current commitment state of every web page. Decommitting a web page releases its physical storage, both in memory or in the paging file on disk. If a web page is decommitted but not launched, its state modifications to reserved. Subsequently, you may name VirtualAlloc to commit it, or VirtualFree to launch it. Makes an attempt to learn from or write to a reserved page leads to an entry violation exception.


The VirtualFree operate can launch a range of pages which can be in different states, some reserved and Memory Wave Method some committed. This implies which you can launch a spread of pages with out first determining the present commitment state of each page. The whole vary of pages initially reserved by the VirtualAlloc perform should be launched at the identical time. If a web page is released, Memory Wave its state adjustments to free, and it is offered for subsequent allocation operations. After memory is released or decommited, you may by no means seek advice from the memory again. Any data that may have been in that memory is gone perpetually. Trying to learn from or write to a free web page ends in an access violation exception. When you need to maintain data, don't decommit or free memory that comprises the knowledge. The VirtualFree operate can be used on an AWE area of Memory Wave Method, and it invalidates any bodily web page mappings within the area when freeing the address area. Nonetheless, the physical web page just isn't deleted, and the appliance can use them. The application should explicitly call FreeUserPhysicalPages to free the physical pages. When the process is terminated, all resources are cleaned up automatically. Home windows 10, model 1709 and later and Windows 11: To delete the enclave once you end utilizing it, name DeleteEnclave. You cannot delete a VBS enclave by calling the VirtualFree or VirtualFreeEx perform. You possibly can nonetheless delete an SGX enclave by calling VirtualFree or VirtualFreeEx. The base deal with of the enclave for the lpAddress parameter. Zero for the dwSize parameter. Release for the dwFreeType parameter.