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

📄 cmemory.cpp

📁 face recognition test source code
💻 CPP
字号:
#include "stdafx.h"

#include "CMemory.h"
#include "error.h"
#include "str.h"
#include "utilcpp.h"
#include <iostream.h>

CMemory::CMemory()
	{
	handle = NULL;
	}

CMemory::~CMemory()
	{	
	if (handle == NULL)
		return;
		
	GlobalUnlock(handle);
	GlobalFree(handle);
	}        
	
void FAR *CMemory::GetPtr()
	{
	int err = 0;
	
	if (handle == NULL)
		{
		err = ERR_MEM_GETPTR;
		Msg(0, str_ERR_MEM_GETPTR);
		Fail(err);											/*Memory was not allocated*/
		}
	
	return GlobalLock(handle);							/*Lock the memory handle and dereference the handle*/
	}

int CMemory::ReleasePtr()
	{
	if (handle == 0)
		return 0;
	
	GlobalUnlock(handle);
	return 0;
	}
	
int CMemory::Allocate(long lsizet)
	{
	int err = 0;
	
	lsize = lsizet;
	
	handle = GlobalAlloc(GHND, lsize);
	if (handle == NULL)
		{
		err = ERR_MEM_ALLOCATE;
		Msg(0, str_ERR_MEM_ALLOCATE);
		Fail(err);											/*Memory cannot be allocated*/
		}
	
	return err;
	}
	
int CMemory::Reallocate(long lsizet)
	{
	int err = 0;
#if 0	
	CMemory temp_mem;
	void FAR *temp_data, FAR *data;
	
	temp_mem.Allocate(lsize);
	temp_data = temp_mem.GetPtr();
	data = GetPtr();
	memcpy(temp_data, data, lsize);
	ReleasePtr();
#endif
	
	GlobalReAlloc(handle, lsizet, GMEM_ZEROINIT);
	
	if (handle == 0)
		{
		err = ERR_MEM_REALLOCATE;
		Msg(0, str_ERR_MEM_REALLOCATE);
		Fail(err);										/*Memory cannot be allocated*/
		}
#if 0
	data = GetPtr();
	memcpy(data, temp_data, lmin(lsize, lsizet));
	ReleasePtr();
	temp_mem.ReleasePtr();
#endif	
	lsize = lsizet;
			
	return err;
	}  
	
long CMemory::GetSize()
	{return lsize;}
	
HGLOBAL CMemory::GetHandle()
	{return handle;}

⌨️ 快捷键说明

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