|
|
4#

楼主 |
发表于 2008-11-25 14:54:01
|
只看该作者

让.Net 应用程序突破2G的内存访问限制
首先先通过VirtualAlloc函数申请一块32位虚拟内存区域
然后通过 MapUserPhysicalPages API 函数将AWE内存映射到这个虚拟内存地址区域。
以下为引用的内容:
public void Map(bool readOnly)
{
unsafe
{
if (IsMapped)
{
return;
}
if (readOnly)
{
_VirtualAddress = AweApi.VirtualAlloc(null, Capacity, AweApi.MEM_RESERVE | AweApi.MEM_PHYSICAL,
AweApi.PAGE_READONLY);
}
else
{
_VirtualAddress = AweApi.VirtualAlloc(null, Capacity, AweApi.MEM_RESERVE | AweApi.MEM_PHYSICAL,
AweApi.PAGE_READWRITE);
}
if (_VirtualAddress == null)
{
throw new AweStreamException("Cannot reserve memory.", AweStreamException.Reason.CannotReserveMemory);
}
if (!AweApi.MapUserPhysicalPages(_VirtualAddress, _NumberOfPages, _PFNArray))
{
AweApi.VirtualFree(_VirtualAddress, Capacity, AweApi.MEM_RELEASE);
_VirtualAddress = null;
throw new AweStreamException(string.Format("MapUserPhysicalPages failed ({0})", General.GetLastError()),
AweStreamException.Reason.MapUserPhysicalPagesFail);
}
_CanWrite = !readOnly;
}
}
去映射和归还AWE内存的过程是上面两个过程的逆过程,这里就不再多讲,有兴趣可以看我的代码。
下面是实例代码下载位置
源代码地址 |
|