VirtualFree Operate (Memoryapi.h)
Releases, decommits, or releases and decommits a region of pages within the digital address area of the calling process. To free memory allotted in one other course of by the VirtualAllocEx perform, use the VirtualFreeEx perform. A pointer to the bottom deal with of the region of pages to be freed. Launch, this parameter should be the bottom deal with returned by the VirtualAlloc perform when the area of pages is reserved. The dimensions of the region of memory to be freed, in bytes. Release, this parameter must be zero (zero). The perform frees the whole region that is reserved within the preliminary allocation name to VirtualAlloc. Dimension). This implies, for example, that a 2-byte region of memory that straddles a web page boundary causes each pages to be decommitted. If lpAddress is the bottom deal with returned by VirtualAlloc and dwSize is 0 (zero), the operate decommits the whole area that is allocated by VirtualAlloc.
After that, your complete region is in the reserved state. The type of free operation. This parameter have to be certainly one of the following values. The perform does not fail when you try and decommit an uncommitted page. This implies that you could decommit a range of pages without first determining the present commitment state. DECOMMIT worth is just not supported when the lpAddress parameter provides the base tackle for an enclave. That is true for enclaves that don't assist dynamic memory management (i.e. SGX1). DECOMMIT wherever in the enclave. For those who specify this value, dwSize must be 0 (zero), and lpAddress should level to the base deal with returned by the VirtualAlloc function when the region is reserved. The operate fails if both of those circumstances just isn't met. If any pages within the area are committed at the moment, the perform first decommits, after which releases them. The function doesn't fail for those who attempt to launch pages that are in different states, some reserved and a few committed.
This implies that you could release a range of pages with out first figuring out the current dedication state. Launch, this parameter can additionally specify one in all the next values. If the perform succeeds, the return value is nonzero. If the operate fails, the return value is 0 (zero). To get prolonged error info, call GetLastError. Each web page of memory in a course of digital deal with space has a Page State. The VirtualFree perform can decommit a range of pages which are in different states, some dedicated focus and concentration booster a few uncommitted. This implies you can decommit a range of pages with out first figuring out the current commitment state of each web page. Decommitting a web page releases its physical storage, either in memory or in the paging file on disk. If a web page is decommitted but not released, its state changes to reserved. Subsequently, you possibly can name VirtualAlloc to commit it, or VirtualFree to launch it. Makes an attempt to learn from or write to a reserved web page ends in an access violation exception.
The VirtualFree operate can launch a variety of pages that are in different states, some reserved and some committed. This implies that you could launch a variety of pages without first determining the current commitment state of every web page. Your complete range of pages initially reserved by the VirtualAlloc function have to be released at the same time. If a web page is launched, its state modifications to free, and it is obtainable for subsequent allocation operations. After memory is launched or decommited, you possibly can by no means refer to the memory again. Any information which will have been in that memory is gone perpetually. Making an attempt to learn from or write to a free web page ends in an entry violation exception. If you happen to want to maintain data, do not decommit or free memory that contains the knowledge. The VirtualFree operate can be utilized on an AWE area of memory, and it invalidates any physical web page mappings in the region when freeing the address area. Nevertheless, the physical web page will not be deleted, and the appliance can use them. The appliance must explicitly call FreeUserPhysicalPages to free the bodily pages. When the method is terminated, all assets are cleaned up robotically. Windows 10, version 1709 and later and Home windows 11: To delete the enclave whenever you finish using it, name DeleteEnclave. You can not 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 tackle of the enclave for the lpAddress parameter. 0 for the dwSize parameter. Release for the dwFreeType parameter.