Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
DynamicArray.cpp
Package: LegendOfMir2_Server020418.zip [view]
Upload User: szopptop
Upload Date: 2013-04-23
Package Size: 1047k
Code Size: 1k
Category:
Game Server Simulator
Development Platform:
Visual C++
- #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);
- }
- }