hangzhoustayer
驱动小牛
驱动小牛
  • 注册日期2002-05-08
  • 最后登录2006-06-19
  • 粉丝1
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1784回复:8

请教ExAllocatePool与ExAllocatePool在分配内存时有什么不同

楼主#
更多 发布于:2005-01-11 20:17
一般为自己定义的结构变量分配内存应该使用哪个?谢谢
aiwadgj
驱动老牛
驱动老牛
  • 注册日期2004-11-13
  • 最后登录2020-12-24
  • 粉丝0
  • 关注0
  • 积分119分
  • 威望84点
  • 贡献值0点
  • 好评度14点
  • 原创分0分
  • 专家分0分
  • 社区居民
沙发#
发布于:2005-01-11 21:54
两个是一样的哦???、

酒也在沉溺,何时麻醉我抑郁。过去了的一切会平息。。。。。。。
AllenZh
驱动老牛
驱动老牛
  • 注册日期2001-08-19
  • 最后登录2015-11-27
  • 粉丝19
  • 关注10
  • 积分1316分
  • 威望2387点
  • 贡献值7点
  • 好评度321点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2005-01-11 22:45
一般为自己定义的结构变量分配内存应该使用哪个?谢谢

是呀"请教ExAllocatePool与ExAllocatePool在分配内存时有什么不同 "中的函数是相同的喔
1,承接Windows下驱动/应用开发 2,本人原创虚拟鼠标/键盘,触摸屏,虚拟显卡,Mirror驱动,XP无盘的SCSI虚拟磁盘驱动等 3,windows下有尝技术服务(包括BUG调试,员工培训等) 欢迎深圳和海外企业联系.msn:mfczmh@sina.com
fslife
驱动大牛
驱动大牛
  • 注册日期2004-06-07
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分9分
  • 威望49点
  • 贡献值0点
  • 好评度20点
  • 原创分0分
  • 专家分0分
地板#
发布于:2005-01-12 13:28
肯定是敲错了。。。
在交流中学习。。。
hangzhoustayer
驱动小牛
驱动小牛
  • 注册日期2002-05-08
  • 最后登录2006-06-19
  • 粉丝1
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2005-01-12 13:30
-_-不好意思,是NdisAllocateMemory与ExAllocatePool...
snowStart
驱动老牛
驱动老牛
  • 注册日期2004-04-06
  • 最后登录2011-06-02
  • 粉丝0
  • 关注0
  • 积分95分
  • 威望19点
  • 贡献值177点
  • 好评度1点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2005-01-13 08:27
NdisAllocateMemory 是NDIS/TDI/NIC/IM专用的

NdisAllocateMemory allocates resident (nonpaged) system-space memory, optionally within a specified address limit, as a physically contiguous allocation, and/or as a noncached allocation.
Comments
Any NDIS driver might call NdisAllocateMemory with the MemoryFlags set to zero. For example, NDIS drivers that export a set of NDIS upper-edge (MiniportXxx) functions can call NdisAllocateMemory to allocate a context area in which the driver will maintain per-NIC (or per-virtual-NIC) runtime state information and pass the pointer returned at VirtualAddress to NdisMSetAttributes(Ex). NDIS drivers that export a set of NDIS lower-edge (ProtocolXxx) functions also can call NdisAllocateMemory whenever such a driver needs to allocate buffer space.

Only miniport drivers can set the MemoryFlags with either or both of the NDIS_MEMORY_XXX when they make initialization-time calls to NdisAllocateMemory. During initialization, miniport drivers allocate these types of memory to be shared with their NICs.

If such a miniport driver specifies physically contiguous memory in a call to NdisAllocateMemory, the virtual memory allocation maps to a single physically contiguous region. If a miniport driver specifies noncached memory, the allocated virtual range is not cached. A NIC driver can access noncached memory without flushing cache buffers during DMA operations.

Whatever the value of the input MemoryFlags, a successful caller of NdisAllocateMemory uses a range of virtual addresses to access the allocated memory. Depending on the size of the allocation and on the type of memory requested, one or more physical memory ranges (pages) back this single virtual range.

While the NDIS_MEMORY_XXX can be ORed in MemoryFlags to request a contiguous and noncached allocation by a NIC driver, both contiguous and noncached memory are very limited system resources. A NIC driver should never request more contiguous memory and/or more noncached memory than it needs. Attempts to allocate either of these types of memory except during driver initialization are a programming error. Such an attempt is unlikely to be successful because system-space memory becomes fragmented due to allocations by other kernel-mode components, including other drivers, and due to runtime paging.

If such an initialization-time call fails, a NIC driver can attempt to allocate one or more smaller blocks of contiguous and/or noncached memory, rather than failing to initialize if it cannot allocate a large block.

Callers of NdisAllocateMemory can run at IRQL <= DISPATCH_LEVEL to allocate memory from nonpaged pool. NIC drivers that allocate contiguous and/or noncached memory must be running at IRQL PASSIVE_LEVEL during initialization.

ExAllocatePool 通用的
ExAllocatePool allocates pool memory of the specified type and returns a pointer to the allocated block.

Comments
This routine is used for general pool allocation of memory.

If the NumberOfBytes requested is PAGE_SIZE or greater, a page-aligned buffer is allocated. Memory allocations of PAGE_SIZE or less do not cross page boundaries. Memory allocations of less than PAGE_SIZE are not necessarily page-aligned but are aligned on an 8-byte boundary.

A successful allocation requesting NumberOfBytes < PAGE_SIZE of nonpaged pool gives the caller exactly the number of requested bytes of memory. Any successful allocation that requests NumberOfBytes > PAGE_SIZE wastes all unused bytes on the last-allocated page.

Callers of ExAllocatePool must be running at IRQL <= DISPATCH_LEVEL. A caller at DISPATCH_LEVEL must specify a NonPagedXxx PoolType. Otherwise, the caller must be running at IRQL < DISPATCH_LEVEL.

If ExAllocatePool returns NULL, the caller should return the NTSTATUS value STATUS_INSUFFICIENT_RESOURCES or should delay processing to another point in time.

学习,关注,交流中... [email=fengyu@163.com]Email:snowstarth@163.com[/email] [url]http://bbs.zndev.com/?a=snowStart[/url]
hangzhoustayer
驱动小牛
驱动小牛
  • 注册日期2002-05-08
  • 最后登录2006-06-19
  • 粉丝1
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2005-01-13 09:30
哦,谢谢
那RtlZeroMemory与NdisZeroMemory呢
wowocock
VIP专家组
VIP专家组
  • 注册日期2002-04-08
  • 最后登录2016-01-09
  • 粉丝16
  • 关注2
  • 积分601分
  • 威望1651点
  • 贡献值1点
  • 好评度1227点
  • 原创分1分
  • 专家分0分
7楼#
发布于:2005-01-13 14:03
#define ALLOC_FROM_POOL(_Size_, _Tag_) ExAllocatePoolWithTag(NonPagedPool,   _Size_,   _Tag_)
NDIS_STATUS
NdisAllocateMemory(
OUT PVOID * VirtualAddress,
IN UINT Length,
IN UINT MemoryFlags,
IN NDIS_PHYSICAL_ADDRESS HighestAcceptableAddress
)
/*++

Routine Description:

Allocate memory for use by a protocol or a MAC driver

Arguments:

VirtualAddress - Returns a pointer to the allocated memory.
Length - Size of requested allocation in bytes.
MaximumPhysicalAddress - Highest addressable address of the allocated
memory.. 0 means highest system memory possible.
MemoryFlags - Bit mask that allows the caller to specify attributes
of the allocated memory.  0 means standard memory.

other options:

NDIS_MEMORY_CONTIGUOUS
NDIS_MEMORY_NONCACHED

Return Value:

NDIS_STATUS_SUCCESS if successful.
NDIS_STATUS_FAILURE if not successful.  *VirtualAddress will be NULL.


--*/
{
//
// Depending on the value of MemoryFlags, we allocate three different
// types of memory.
//

if (MemoryFlags == 0)
{
*VirtualAddress = ALLOC_FROM_POOL(Length, NDIS_TAG_ALLOC_MEM);
}
else if (MemoryFlags & NDIS_MEMORY_NONCACHED)
{
*VirtualAddress = MmAllocateNonCachedMemory(Length);
}
else if (MemoryFlags & NDIS_MEMORY_CONTIGUOUS)
{
*VirtualAddress = MmAllocateContiguousMemory(Length, HighestAcceptableAddress);
}

return (*VirtualAddress == NULL) ? NDIS_STATUS_FAILURE : NDIS_STATUS_SUCCESS;
}

#define NdisZeroMemory(Destination, Length) RtlZeroMemory(Destination, Length)
花开了,然后又会凋零,星星是璀璨的,可那光芒也会消失。在这样 一瞬间,人降生了,笑者,哭着,战斗,伤害,喜悦,悲伤憎恶,爱。一切都只是刹那间的邂逅,而最后都要归入死亡的永眠
hangzhoustayer
驱动小牛
驱动小牛
  • 注册日期2002-05-08
  • 最后登录2006-06-19
  • 粉丝1
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
8楼#
发布于:2005-01-13 14:10
哦,知道了,多谢多谢
游客

返回顶部