The Collections class mainly includes three forms and their different applications:
Array - Carray, Cobarray, CstringArray, CPTRARRAY, CBYTEARRAY, CWORDARRAY, CDWORDARRAY, CTYPTRARRAY
List - Clist, Coblist, CStringList, Cptrlist
CMAP - CMAP, CTYPTRMAP, CMAPPTRTOPTR, CMAPPTRTOWORD, CMAPWORDTOPTR, CMAPSTRINGTOPTR
Overall comparison:
Attribute class feature memory structure Array See: type * pnewdata = (Type *) in VC Source CARRAY:: TYPE * PNEWDATA = (TYPE *)]; // Copy New Data from OldMemcpy (PNewData, m_pData, m_nSize * sizeof (TYPE)); // construct remaining elementsASSERT (nNewSize> m_nSize); ConstructElements
As can be seen in the CHARACTERISTICS table below, the value of Key is not repetitive, ie, can only be unique (for example, there is no statement of two identical names in the same program in the previous example), and Value can be repeated ( The class of different names can have exactly the same variables and functions). Despite the high-efficiency search mode, a large number of cMap: lookup () functions is still very time consuming, 400 000 lookup () execution time is about 1 second, and the same number of Cobarray :: getat () functions only It takes 0.3 seconds. Application Skills Array1 If in the case you use, the following cases appear: a. The size of the data element is large B. You often need to perform the Add function (for example, when the database is executing the SELECT statement), you need to perform setsize in advance (int nsize) , int NGROWBY) function, determine the approximate size in advance (then can still increase) and the number of memory applications at the time of time, thereby avoiding frequent memory applications, copying, and deleting work frequently. 2 All names of the PTR containing PTR do not delete memory work, you need to do it yourself. 3 If the REMOVEAT () function is involved in the cycle, the loop must start from the tail, otherwise the element may miss the element, an example: ctypedptraray
Collection Shape Features
SHAPEORDERED? INDEXED? INSERT AN ElementSearch for specified ElementDuplicate Elements? ListyesnofastslowyesarayyESBY INTSLOWYESMAPNOBY Keyfastfastno (keys) Yes (VALUES) YES
Characteristics Of MFC Collection Classes
ClassUses C templatesCan be serializedCan be dumpedIs type-safeCArrayYesYes 1Yes 1NoCByteArrayNoYesYesYes 3CDWordArrayNoYesYesYes 3CListYesYes 1Yes 1NoCMapYesYes 1Yes 1NoCMapPtrToPtrNoNoYesNoCMapPtrToWordNoNoYesNoCMapStringToObNoYesYesNoCMapStringToPtrNoNoYesNoCMapStringToStringNoYesYesYes 3CMapWordToObNoYesYesNoCMapWordToPtrNoNoYesNoCObArrayNoYesYesNoCObListNoYesYesNoCPtrArrayNoNoYesNoCPtrListNoNoYesNoCStringArrayNoYesYesYes 3CStringListNoYesYesYes 3CTypedPtrArrayYesDepends 2YesYesCTypedPtrListYesDepends 2YesYesCTypedPtrMapYesDepends 2YesYesCUIntArrayNoNoYesYes 3CWordArrayNoYesYesYes 31. To serialize, you must explicitly call the collection object's
Serialize Function; To Dump, You Must Explicitly Call ITS
Dump function. You cannot USE The Form
Ar << Collobj to Serialize or the Form
DMP
<< Collobj to Dump.
2. Serializability depends on the underlying collection type For example, if a typed pointer array is based on CObArray, it is serializable;. If based on CPtrArray, it is not serializable In general, the "Ptr" classes can not be serialized..
3. If marked Yes in this column, a nontemplate collection class is type-safe provided you use it as intended. For example, if you store bytes in a CByteArray, the array is type-safe. But if you use it to store characters , ITS Type Safety Is Less Certain.