1 VirtualFree Perform (Memoryapi.h)
Antony Raven edited this page 2025-09-12 16:10:57 +03:00


Releases, decommits, or releases and decommits a area of pages inside the digital handle house of the calling course of. To free memory allotted in another process by the VirtualAllocEx perform, use the VirtualFreeEx operate. A pointer to the base handle of the region of pages to be freed. Release, this parameter have to be the bottom deal with returned by the VirtualAlloc operate when the area of pages is reserved. The scale of the area of memory to be freed, in bytes. Release, this parameter must be 0 (zero). The operate frees the whole area that is reserved within the initial allocation name to VirtualAlloc. Size). This implies, for instance, that a 2-byte region of memory that straddles a web page boundary causes both pages to be decommitted. If lpAddress is the bottom tackle returned by VirtualAlloc and dwSize is zero (zero), the operate decommits the complete region that is allocated by VirtualAlloc.


After that, your complete region is within the reserved state. The type of free operation. This parameter must be one in every of the next values. The function does not fail should you attempt to decommit an uncommitted web page. This implies you could decommit a spread of pages with out first figuring out the current dedication state. DECOMMIT value shouldn't be supported when the lpAddress parameter offers the bottom handle for an enclave. This is true for enclaves that don't support dynamic memory administration (i.e. SGX1). DECOMMIT anyplace within the enclave. In case you specify this worth, dwSize have to be 0 (zero), and lpAddress should point to the base tackle returned by the VirtualAlloc function when the region is reserved. The function fails if either of those conditions shouldn't be met. If any pages in the region are committed at the moment, the function first decommits, after which releases them. The operate does not fail when you attempt to launch pages which might be in different states, some reserved and a few dedicated.


This means that you can launch a variety of pages with out first figuring out the present dedication state. Launch, this parameter can moreover specify one of the following values. If the function succeeds, the return worth is nonzero. If the operate fails, the return value is zero (zero). To get extended error information, name GetLastError. Each web page of memory in a course of digital tackle area has a Web page State. The VirtualFree function can decommit a spread of pages that are in numerous states, some committed and some uncommitted. This means which you can decommit a spread of pages with out first figuring out the current commitment state of each web page. Decommitting a web page releases its bodily storage, both in memory or within the paging file on disk. If a web page is decommitted but not released, its state adjustments to reserved. Subsequently, you possibly can call VirtualAlloc to commit it, or VirtualFree to release it. Makes an attempt to learn from or write to a reserved web page ends in an entry violation exception.


The VirtualFree function can launch a variety of pages which can be in several states, some reserved and some dedicated. This means that you would be able to launch a spread of pages with out first figuring out the current commitment state of every web page. The complete range of pages originally reserved by the VirtualAlloc perform have to be released at the identical time. If a page is launched, its state adjustments to free, and it is offered for subsequent allocation operations. After memory is launched or decommited, you'll be able to by no means discuss with the memory once more. Any data which will have been in that Memory Wave Method is gone perpetually. Making an attempt to read from or write to a free web page results in an entry violation exception. If you happen to want to keep info, Memory Wave do not decommit or free memory that accommodates the data. The VirtualFree operate can be used on an AWE area of memory, and it invalidates any bodily web page mappings within the area when freeing the address house. Nevertheless, the bodily page will not be deleted, and the applying can use them. The appliance should explicitly name FreeUserPhysicalPages to free the physical pages. When the method is terminated, all resources are cleaned up automatically. Windows 10, model 1709 and later and Home windows 11: To delete the enclave while you end utilizing it, name DeleteEnclave. You cannot delete a VBS enclave by calling the VirtualFree or VirtualFreeEx operate. You possibly can still delete an SGX enclave by calling VirtualFree or VirtualFreeEx. The bottom handle of the enclave for the lpAddress parameter. Zero for the dwSize parameter. Release for the dwFreeType parameter.