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

📄 dynamicarray.cpp

📁 真正的传奇源代码
💻 CPP
字号:
#include "stdafx.h"

CWHDynamicArray::CWHDynamicArray()
{
	InitializeCriticalSection(&m_cs);

	m_nLastRemoveIndex = 0;
	m_nLastInsertIndex = 0;

	for (int i = 0; i < _MAX_USER_ARRAY; i++)
		m_Elements[i] = NULL;
}

CWHDynamicArray::~CWHDynamicArray()
{
	DeleteCriticalSection(&m_cs);
}

int CWHDynamicArray::AttachData(VOID *pElement)
{
	int nIndex = -1;

	EnterCriticalSection(&m_cs);

	__try
	{
		nIndex = m_nLastRemoveIndex;

		if (m_Elements[nIndex] == NULL)
		{
			m_Elements[nIndex] = pElement;
			__leave;
		}

		for (int i = m_nLastInsertIndex; i < _MAX_USER_ARRAY; i++)
		{
			if (m_Elements[nIndex] == NULL)
			{
				m_Elements[nIndex] = pElement;
				m_nLastInsertIndex = nIndex;
				__leave;
			}
		}

		for (i = 0; i < m_nLastInsertIndex; i++)
		{
			if (m_Elements[nIndex] == NULL)
			{
				m_Elements[nIndex] = pElement;
				m_nLastInsertIndex = nIndex;
				break;
			}
		}
	}
	__finally
	{
		LeaveCriticalSection(&m_cs);
	}

	return nIndex;
}

void CWHDynamicArray::DettachData(int nIndex)
{
	EnterCriticalSection(&m_cs);

	__try
	{
		m_Elements[nIndex] = NULL;
		m_nLastRemoveIndex = nIndex;
	}
	__finally
	{
		LeaveCriticalSection(&m_cs);
	}
}

⌨️ 快捷键说明

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