====== template XItemArray ====== **//Inherited from//** NULL **//Inherited by//** NULL **//Friend class//** NULL **//Description//** XItemArray封装了按固定大小N增长的数组,它一般用于在数组长度不是很大的场合,便于直接从内存池中分配,可以避免程序运行中频繁分配释放数组时产生的内存碎片,同时保证数据访问性能。它的容量为N的整数倍,增加数组对象时直接在数组的内存空间中赋值,当对象的个数超过容量时,将数组的容量增长N重新从内存池中申请空间并将旧的空间的值全部拷贝到新的内存空间中,然后将旧的空间放回到内存池中;删除对象时将该对象后面的数据向前挪动一个对象的长度,如果剩余容量小于N,将数组的容量较少N重新从内存池中申请空间并将旧的空间的值全部拷贝到新的内存空间中,然后将旧的空间放回到内存池中。 **//Members//** * T * [[xitemarray#pitemarray|pItemArray]] * int [[xitemarray#iitemcount|iItemCount]] * int [[xitemarray#ivirtualcount|iVirtualCount]] **//Private interface//** * void [[xitemarray#increasecount|increaseCount]]() * void [[xitemarray#decreasecount|decreaseCount]]() * void [[xitemarray#add|add]](XMemPool * mem, const T & item) * void [[xitemarray#remove|remove]](XMemPool * mem, const T & item) * void [[xitemarray#remove|remove]](XMemPool * mem, int i) * void [[xitemarray#removeall|removeAll]](XMemPool * mem) * int [[xitemarray#find|find]](const T & item) const * T & [[xitemarray#at|at]](int index) const * T & operator [[xitemarray#at|[]]] (int index) const * int [[xitemarray#count|count]]() const * void [[xitemarray#clear|clear]](XMemPool * mem) * void [[xitemarray#reserve|reserve]](XMemPool * mem, bool bClear = true) ---- {{anchor:pitemarray}} **T * pItemArray** 对象数组首地址 {{anchor:iitemcount}} **int iItemCount** 对象个数 ---- {{anchor:increasecount}} **void increaseCount()** *function: 对象个数增加1 *parameters: NULL *return value: 无 {{anchor:decreasecount}} **void decreaseCount()** *function: 对象个数减少1 *parameters: NULL *return value: {{anchor:add}} **void add(XMemPool * mem, const T & item)** *function: 向数组中添加一个对象 *parameters: - [i]XMemPool * mem: 内存池 - [i] const T & item: 添加的对象 *return value: 无 {{anchor:remove}} **void remove(XMemPool * mem, const T & item)** *function: 在数组中删除给定对象 *parameters: - [i]XMemPool * mem: 内存池 - [i] const T & item: 删除的对象 *return value: 无 {{anchor:remove}} **void remove(XMemPool * mem, int i)** *function: 删除数组中第i个元素 *parameters: - [i]XMemPool * mem: 内存池 - [i] int i: 元素索引 *return value: 无 {{anchor:removeall}} **void removeAll(XMemPool * mem)** *function: 删除数组所有对象 *parameters: - [i]XMemPool * mem: 内存池 *return value: 无 {{anchor:find}} **int find(const T & item) const** *function: 获取元素在数组中的索引序号 *parameters: - [i]const T & item: 对象元素 *return value: 索引号 {{anchor:at}} **T & at(int index) const** *function: 获取第index个元素的对象引用 *parameters: - [i]int index: 元素索引号 *return value: 对象引用 {{anchor:at}} **T & operator [] (int index) const** *function: 获取第index个元素的对象引用 *parameters: - [i]int index: 元素索引号 *return value: 对象引用 {{anchor:count}} **int count() const** *function: 获取元素的个数 *parameters: NULL *return value: 元素的个数 {{anchor:clear}} **void clear(XMemPool * mem)** *function: 删除数组所有对象,重置数组为最小容量 *parameters: - [i]XMemPool * mem: 内存池 *return value: 无