阅读:989回复:2
如何为每个设备分配一块内存。
作了一个驱动程序,希望为每个设备都分配一块独立的内存。
应该在什么地方加代码?怎么加呢? 我在×××Create()中加入 KIRQL irql; KeAcquireSpinLock(&BufferLock,&irql); ULONG NewBufferSize = 1024; PVOID NewBuffer = ExAllocatePool(NonPagedPool,NewBufferSize); if( NewBuffer == NULL) { DebugPrint(\"Can\'t allocate memory!\"); } else { RtlZeroMemory(NewBuffer,NewBufferSize); Buffer = (PUCHAR)NewBuffer; BufferSize = NewBufferSize; } KeReleaseSpinLock(&BufferLock,irql); 结果变成了所有设备的公共内存。 请指教! |
|
|
沙发#
发布于:2002-07-05 15:34
是不是在OnAddDevice中,我只是猜测
|
|
|
板凳#
发布于:2002-07-05 16:14
这容易,你在
typedef struct _DEVICE_EXTENSION { ... ... UCHAR pBuffer; } DEVICE_EXTENSION, *PDEVICE_EXTENSION; 添加一项pBuffer,然后分配内存 KIRQL irql; PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION) fdo->DeviceExtension; KeAcquireSpinLock(&BufferLock,&irql); ULONG NewBufferSize = 1024; PVOID NewBuffer = ExAllocatePool(NonPagedPool,NewBufferSize); if( NewBuffer == NULL) { DebugPrint(\"Can\'t allocate memory!\"); } else { RtlZeroMemory(NewBuffer,NewBufferSize); pdx->pBuffer = (PUCHAR)NewBuffer; } KeReleaseSpinLock(&BufferLock,irql); 最后记得释放内存 |
|