如何在NT中申请非分页内存?(80分)

  • 主题发起人 主题发起人 quarkfc
  • 开始时间 开始时间
Q

quarkfc

Unregistered / Unconfirmed
GUEST, unregistred user!
我想提高程序的运行效率,在物理内存中分配一3M左右的内存,但又担心<br>NT会把我的内存放到虚拟内存---硬盘上。 <br>&nbsp;请问哪位大使能否告诉我如何分配物理内存啊?
 
GlobalAlloc, 如果你的内存足够大的话应该不会放到PageFile上的.<br><br>注意在option中的设置, 必需保证程序初始时刻占有那么大的堆栈空间
 
应该使用virtual memory functions:<br><br>VirtualAlloc &nbsp;-- Reserves or commits a region of pages in the virtual<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;address space of the calling process.<br>VirtualLock &nbsp; -- Locks the specified region of the process's virtual<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;address space into physical memory, ensuring that <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;subsequent access to the region will not incur a page fault.<br>VirtualUnlock -- Unlocks a specified range of pages in the virtual address<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;space of a process, enabling the system to swap the pages<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;out to the paging file if necessary. <br>VirtualFree &nbsp; -- releases, decommits, or releases and decommits a region of <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pages within the virtual address space of the calling process. <br><br>我向 VirtialLock 提供的保证是你想要的。<br>细节可以参考MSDN -- virtual memory。<br>
 
接受答案了.
 
后退
顶部