Classification: |
C++ |
Category: |
Base |
Created: |
10/19/2000 |
Modified: |
06/15/2001 |
Number: |
FAQ-0532 |
Platform: |
ER5 |
|
Question: Could you give me some tips on the best way to use the array templates, such as CArrayFixedFlat<>, within my objects.
Answer: The RArray<> family of classes is more efficent (particularly time-wise) that the equivalent flat CArray<> classes. If you
can't commit to using a flat array and need to dynamically choose between a ...Flat and ...Seg array then it obviously won't
help.However, if you need to use a flat Carray<> class here are a few pointers. Say you had the following:
class CSemModel : public CBase { private: CArrayPtrFlat iStar; };
i) It is not good practice to have a C-class directly embedded inside another C-class, a pointer to the embedded C-class
should be used:
class CSemModel : public CBase { ... private: CArrayPtrFlat* iStar; };
ii) Although not unknown, it is unusual to have an array of pointers to T-classes (especially T-classes as small as TStar).
The T-classes have to live somewhere so they might as well live in the array itself. So the code changes to:
class CSemModel : public CBase { ... private: CArrayFixFlat* iStar; };
iii) The class definition should use the most abstract definition of the storage structure (in this case CArrayFix):
class CSemModel : public CBase { ... private: CArrayFix* iStar; };
Of course the implementation still uses CArrayFixFlat:
void CSemModel::ConstructL() { iStar = new (ELeave) CArrayFixFlat(EGranularity); }
This allows the implementation to change from using CArrayFixFlat to CArrayFixSeg without changing the header file.
|