VirtualFree Perform (Memoryapi.h)
Releases, decommits, or releases and decommits a region of pages inside the digital tackle area of the calling course of. To free memory allotted in another process by the VirtualAllocEx perform, use the VirtualFreeEx perform. A pointer to the bottom handle of the region of pages to be freed. Release, this parameter have to be the bottom address returned by the VirtualAlloc function when the region of pages is reserved. The dimensions of the region of memory to be freed, in bytes. Release, this parameter have to be 0 (zero). The function frees your complete region that's reserved within the initial allocation call to VirtualAlloc. Size). 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 bottom deal with returned by VirtualAlloc and dwSize is zero (zero), the perform decommits the complete region that is allotted by VirtualAlloc.
After that, the complete region is in the reserved state. The kind of free operation. This parameter must be one in every of the following values. The operate doesn't fail in case you try to decommit an uncommitted web page. This implies that you may decommit a range of pages with out first determining the present commitment state. DECOMMIT worth is not supported when the lpAddress parameter supplies the base deal with for an enclave. This is true for enclaves that don't assist dynamic memory management (i.e. SGX1). DECOMMIT anyplace within the enclave. When you specify this worth, dwSize should be zero (zero), and lpAddress should point to the base deal with returned by the VirtualAlloc perform when the area is reserved. The function fails if either of these conditions shouldn't be met. If any pages in the area are dedicated presently, the perform first decommits, and then releases them. The perform does not fail for those who try to release pages which might be in several states, some reserved and a few dedicated.
This implies that you can release a variety of pages without first figuring out the current commitment state. Release, this parameter can additionally specify one in every of the next values. If the perform succeeds, the return worth is nonzero. If the perform fails, the return worth is zero (zero). To get extended error information, call GetLastError. Every page of memory in a course of virtual handle house has a Web page State. The VirtualFree operate can decommit a variety of pages which can be in several states, some dedicated and some uncommitted. This means you can decommit a range of pages with out first determining the current dedication state of each web page. Decommitting a page releases its physical storage, both in memory or in the paging file on disk. If a page is decommitted however not launched, its state modifications to reserved. Subsequently, you possibly can call VirtualAlloc to commit it, or VirtualFree to release it. Attempts to learn from or write to a reserved page results in an entry violation exception.
The VirtualFree operate can release a spread of pages which might be in numerous states, some reserved and a few committed. This means that you would be able to release a spread of pages with out first figuring out the current commitment state of every page. The complete range of pages originally reserved by the VirtualAlloc operate should be launched at the same time. If a page is released, its state adjustments to free, and it is on the market for subsequent allocation operations. After memory is released or decommited, you possibly can by no means discuss with the memory once more. Any information which will have been in that Memory Wave Program is gone without end. Making an attempt to learn from or write to a free web page leads to an entry violation exception. In the event you need to maintain data, do not decommit or free memory that contains the information. The VirtualFree function can be used on an AWE region of memory, and it invalidates any bodily page mappings in the region when freeing the handle area. Nevertheless, the physical web page just isn't deleted, and the appliance can use them. The applying should explicitly name FreeUserPhysicalPages to free the physical pages. When the method is terminated, all assets are cleaned up mechanically. Home windows 10, model 1709 and later and Windows 11: Memory Wave Program To delete the enclave once you finish using it, call DeleteEnclave. You can not delete a VBS enclave by calling the VirtualFree or VirtualFreeEx operate. You'll be able to still delete an SGX enclave by calling VirtualFree or VirtualFreeEx. The bottom address of the enclave for the lpAddress parameter. 0 for the dwSize parameter. Launch for the dwFreeType parameter.