cmemory.hpp

来自「bt848,bt878 a采集卡的探测」· HPP 代码 · 共 57 行

HPP
57
字号
// A Memory block class

#ifndef _CMEMORY_HPP
#define _CMEMORY_HPP

#include <windows.h>

// Be careful, there is no copy on write!! - All owners of references will see the changes!
class CString;

class CMemory {
protected:

	// Our memory atom class
	class CMemoryAtom {
	protected:

		void* block;		// Memory block
		UINT  len;			// Length of block
		UINT  refcount;		// reference count

	public:
		CMemoryAtom(const UINT thelen = 0);
		bool	IsOk()		const { return (block != NULL); }
		bool	ReSize(const UINT Amount);
		UINT	Size()		const { return len; }
		void*	Ptr()		const { return block; }
		UINT	RefCount()	const { return refcount; } 
		void	AddRef()	{ refcount++; }
		bool	Release();
		~CMemoryAtom();
	};

protected:
	
	CMemoryAtom* atom;		// My memory atom

public:

	CMemory(const UINT thelen = 0) : atom(new CMemoryAtom(thelen)) {}
	CMemory(CMemory& blk) : atom(0) { atom = blk.atom; atom->AddRef(); }
	CMemory& operator=(CMemory& blk);

	bool IsOk() const { return atom->IsOk(); }
	bool ReSize(const UINT Amount) { return atom->ReSize(Amount); }
	UINT Size() const { return atom->Size(); }
	void* Ptr() const { return atom->Ptr(); }
	~CMemory();

	// Some useful fns
	friend CMemory LoadBinaryResource(HINSTANCE instance,LPCTSTR res,LPCTSTR type = RT_RCDATA);
	friend CMemory LoadBinaryFile(LPTSTR File);
	friend CMemory LoadBinaryFile(CString& File);

};

#endif

⌨️ 快捷键说明

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