15-内存的申请释放
申请内存的两种方式:
- 通过VirtualAlloc/VirtualAllocEx申请的:Private Memory
独占物理页
LPVOID VirtualAlloc(
LPVOID lpAddress,
// 要分配的内存地址,通常为null即可
DWORD dwSize,
// 分配内存的大小
DWORD flAllocationType,
// 分配的内存类型
DWORD flProtect
// 该内存的初始保护属性
);- 通过CreateFileMapping映射的:Mapped Memory 共享物理页
HANDLE CreateFileMapping(
HANDLE hFile,
// handle to file to map
LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
// optional security attributes
DWORD flProtect,
// protection for mapping object
DWORD dwMaximumSizeHigh,
// high-order 32 bits of object size
DWORD dwMaximumSizeLow,
// low-order 32 bits of object size
LPCTSTR lpName
// name of file-mapping object
);释放内存api
BOOL VirtualFree(
LPVOID lpAddress,
// address of region of committed pages
DWORD dwSize,
// size of region
DWORD dwFreeType
// type of free operation
);
评论讨论 (0) Artalk 自托管