smappedmemory.h

来自「PGP8.0源码 请认真阅读您的文件包然后写出其具体功能」· C头文件 代码 · 共 72 行

H
72 行
字号
/*____________________________________________________________________________
		Copyright (C) 2002 PGP Corporation
        All rights reserved.

        $Id: SMappedMemory.h,v 1.2 2002/08/06 20:09:34 dallen Exp $
____________________________________________________________________________*/

#ifndef Included_SMappedMemory_h	// [
#define Included_SMappedMemory_h

#include "CErrorState.h"

#include "CDriverSubsystems.h"
#include "CMemoryLocker.h"

_PGP_BEGIN

// Class SMappedMemory

// SMappedMemory is a helper class that wraps calls to lock/unlock memory
// from user mode.

template <typename T> class SMappedMemory : public CErrorState
{
	NOT_COPYABLE(SMappedMemory)

public:
			SMappedMemory(const T *pObject, PGPUInt32 size = sizeof(T));
	virtual	~SMappedMemory();

	PGPUInt32	Size() const {return mSize;}

	T *			MappedAddress() {return const_cast<T *>(mMappedObject);}
	const T *	MappedAddress() const {return mMappedObject;}


private:
	const T	*mObject;
	const T	*mMappedObject;

	PGPUInt32	mSize;
};


// Class SMappedMemory template member functions

template <typename T> 
inline 
SMappedMemory<T>::SMappedMemory(const T *pObject, PGPUInt32 size) 
	: mObject(pObject), mSize(size)
{
	void	*mappedAddress;

	Status() = CDriverSubsystems::MemoryLocker().LockMemory(pObject, size, 
		&mappedAddress);

	if (Status().IsntError())
		mMappedObject = static_cast<const T *>(mappedAddress);
}

template <typename T> 
inline 
SMappedMemory<T>::~SMappedMemory()
{
	if (Status().IsntError())
		CDriverSubsystems::MemoryLocker().UnlockMemory(mObject);
}

_PGP_END

#endif	// Included_SMappedMemory_h

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?