阅读:1844回复:8
请教ExAllocatePool与ExAllocatePool在分配内存时有什么不同
一般为自己定义的结构变量分配内存应该使用哪个?谢谢
|
|
沙发#
发布于:2005-01-11 21:54
两个是一样的哦???、
|
|
|
板凳#
发布于:2005-01-11 22:45
一般为自己定义的结构变量分配内存应该使用哪个?谢谢 是呀"请教ExAllocatePool与ExAllocatePool在分配内存时有什么不同 "中的函数是相同的喔 |
|
|
地板#
发布于:2005-01-12 13:28
肯定是敲错了。。。
|
|
|
地下室#
发布于:2005-01-12 13:30
-_-不好意思,是NdisAllocateMemory与ExAllocatePool...
|
|
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. |
|
|
6楼#
发布于:2005-01-13 09:30
哦,谢谢
那RtlZeroMemory与NdisZeroMemory呢 |
|
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) |
|
|
8楼#
发布于:2005-01-13 14:10
哦,知道了,多谢多谢
|
|