小技巧,使用CArray——Using CArray
来源:互联网 发布:社交软件排名 编辑:程序博客网 时间:2024/05/16 19:29
CArray的定义是:
Parameters
- TYPE
Template parameter specifying the type of objects stored in the array. TYPE is a parameter that is returned by CArray.
- ARG _ TYPE
Template parameter specifying the argument type used to access objects stored in the array. Often a reference to TYPE. ARG_TYPE is a parameter that is passed to CArray.
Array indexes always start at position 0. You can decide whether to fix the upper bound or allow the array to expand when you add elements past the current bound. Memory is allocated contiguously to the upper bound, even if some elements are null.
As with a C array, the access time for a CArray indexed element is constant and is independent of the array size.
Before using an array, use SetSize to establish its size and allocate memory for it. If you do not use SetSize, adding elements to your array causes it to be frequently reallocated and copied. Frequent reallocation and copying are inefficient and can fragment memory.
If you need a dump of individual elements in an array, you must set the depth of the CDumpContext object to 1 or greater.
Certain member functions of this class call global helper functions that must be customized for most uses of the CArray class. See the topic Collection Class Helpers in the MFC Macros and Globals section.
Array class derivation is similar to list derivation.
For more information on using CArray, see the article Collections.
有个小技巧是可以这样使用:
完整的CArray定义如下:
CArray
Constructs an empty array.
GetCount
Gets the number of elements in this array.
GetSize
Gets the number of elements in this array.
GetUpperBound
Returns the largest valid index.
IsEmpty
Determines whether the array is empty.
SetSize
Sets the number of elements to be contained in this array.
FreeExtra
Frees all unused memory above the current upper bound.
RemoveAll
Removes all the elements from this array.
RelocateElements
Relocates data to a new buffer when the array should grow or shrink.
ElementAt
Returns a temporary reference to the element pointer within the array.
GetAt
Returns the value at a given index.
GetData
Allows access to elements in the array. Can be NULL.
SetAt
Sets the value for a given index; array not allowed to grow.
Add
Adds an element to the end of the array; grows the array if necessary.
Append
Appends another array to the array; grows the array if necessary
Copy
Copies another array to the array; grows the array if necessary.
SetAtGrow
Sets the value for a given index; grows the array if necessary.
InsertAt
Inserts an element (or all the elements in another array) at a specified index.
RemoveAt
Removes an element at a specific index.
operator []
Sets or gets the element at the specified index.
- 小技巧,使用CArray——Using CArray
- CArray
- CArray
- CArray
- CArray
- CArray
- CArray
- CArray
- CArray
- CArray
- CArray
- CArray
- CArray
- CArray的使用
- CArray的使用
- 如何使用CArray
- CArray使用一点
- CArray如何使用
- NeHe OpenGL教程 (二十八)
- 使用sem_t导致不能用gdb调试及线程非正常终止后message queue异常的问题
- 求导
- 一个非常专业的SaaS应用,学习的目标
- C#操作Excel
- 小技巧,使用CArray——Using CArray
- 简单的证明预编译不进行语法检查
- C++子类显示调用父类的构造函数
- dom解析xml文件
- TC++PL Chapter 6 读书笔记
- poj 1077 EIGHT
- 南航acm1077_滑雪
- 提高网站的流量?
- 怎样更新Android SDK1.1 到 Android SDK1.5