⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memorybuffer.h

📁 WinCE 3.0 BSP, 包含Inter SA1110, Intel_815E, Advantech_PCM9574 等
💻 H
字号:
// MemoryBuffer.h: interface for the CMemoryBuffer class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MEMORYBUFFER_H__79C61CE1_F64C_49C9_AD6B_368D1B13867D__INCLUDED_)
#define AFX_MEMORYBUFFER_H__79C61CE1_F64C_49C9_AD6B_368D1B13867D__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// a couple of memory saving defines (the *programmer's* memory, that is)


struct SMemoryChunk
{
	ULONG	m_ulAddress;
	ULONG	m_ulSize;
};



// the class manages a memory buffer with support for scatter-gather DMA 
// The virtual memory buffer is logically contiguous, but it's represented 
// by an array of physical pages that may not be so. 
// The class reserves contiguous or non-contiguous memory, and consolidates contiguous pages 
// into chunks.
// 
class CMemoryBuffer  
{

public:
	CMemoryBuffer();
	virtual ~CMemoryBuffer();

	bool ReservePhysicalMem(ULONG dwSize);
	
	// access functions
	UINT	GetNumberOfChunks(void){return m_nChunks;}
	ULONG	GetPhysicalAddress(){return IsContiguous()?GetChunkAddress(0):ULONG(-1);}
	ULONG	GetChunkAddress(UINT uChunk){return (uChunk >= m_nChunks)? ULONG(-1) : m_pChunks[uChunk].m_ulAddress;}
	ULONG	GetChunkSize(UINT uChunk){return (uChunk >= m_nChunks)?ULONG(-1):m_pChunks[uChunk].m_ulSize;};
	LPBYTE GetVirtualAddress(){return m_pVirtualAddress;};			// the virtual address
	DWORD GetSize(){return m_ulSize;};
	bool  IsContiguous(){return 1 == m_nChunks;}

protected:
	void FreeBuffer(void);

protected:
	struct SMemoryChunk	*m_pChunks;		// the physical addresses and sizes of the (locked) memory chunks
	LPBYTE	m_pVirtualAddress;			// the virtual address
	ULONG	m_ulSize;			// the total size of the buffer
	UINT	m_nChunks;		// the number of entries in the m_pPhysAddresses table

};

#endif // !defined(AFX_MEMORYBUFFER_H__79C61CE1_F64C_49C9_AD6B_368D1B13867D__INCLUDED_)

⌨️ 快捷键说明

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