Symbian中的Array


Flat vs Seg

The implementationof dynamic array can be:

  1. a single heap cell as ”flat” buffer to hold the array elements
  2. ;
  1. a number of heap segments as "seg" (using doubly-linked list) to hold the array elements
  2. .

 

 Fix – Ptr – Var - Pak

Fix: elements should have the same length. When a element is appended, it will becopied and the newly copied element will be added to the array buffer.

The InsertIsqL( ),Find( ), FindIsqL( ) and Sort( ) of Fix class need a TKeyArrayFix object as anargument to define the location and type of the key within the array element.


Ptr: a specialized Fix, elements are pointers to CBase-derived objects.

Var: elements are of different lengths, each element is contained within its ownheap cell, and the array buffer contains pointers to the element’s cell. When aelement is appended, it will be copied, furthermore, the Var array alwaysattempts to allocate a cell to contain the newly copied element and add apointer to the newly copied element to the array buffer.


The InsertIsqL( ),Find( ), FindIsqL( ) and Sort( ) of Var class need a TKeyArrayVar object as anargument to define the location and type of the key within the array element.

Pak: elements are of different length, and when a element is appended, the elementis copied and contained in the array buffer. Each element is preceded by itslength information.


The InsertIsqL( ),Find(), FindIsqL( ) of Pak class need a TKeyArrayPakobject as an argument to define the location and type of the key within thearray element.

The SortL( ) need aTKeyArrayVar object as an argumentto define the location and type of the key within the array element.

 

Capacity vs Granularity

The capacity ofdynamic array is the number of elements the array can hold within the currentlyallocated buffer.

When the capacityis filled, the array dynamically resizes itself by reallocating heap memorywhen the next element is added. The number of additional elements allocated tothe buffer is determined by the granularity.

 

RArray/RPointerArray

RArray > Flat arrays of Fixed-length objects (CArrayFixFlat)

RPointerArray > Flat arrays of pointers to CBase-derived objects(CArrayPtrFlat)

”R” indicates thatit owns a resource, in the case, the resource is the heap memory allocated tohold the array.

Why Use RArrayInstead of CArrayX?

1.The originalCArrayX class use CBufBase, which works with byte and requires a TPtr8 objectto be constructed for every array access.

2. For every arrayaccess, it will be a minimum of two assertions (CArrayXBase and CBufBase) tocheck the parameters.

3. The arraymanipulation functions of CArrayX, such as AppendL(), can leave. While in somecases, such as in the kernel code, leave is not allowed. In thosecircumstances, the leaving functions must be called in TRAP macro to catchleaves. RArray have non-leave function and do not need a TRAP harness.

4. R class haslower overhead than C class, because R class does not need the characteristicfeatures of C class, such as zero-fill on allocation, virtual function tablepointer and creation on the heap.

5. The searchingand ordering functions of RArray are optimized than CArrayX.

6. The elements containenin RArray and RPointerArray may be ordered using a comparator function providedby the element.

For RPointerArray,you must consider the ownership of elements when you have finished using thearray.

  1. If elements are owned elsewhere, then it is sufficient to call Close() or Reset() to clean up the memory associated with the array.
  2. If elements are owned by the array, they must be destroyed by calling ResetAndDestroy( )

Dynamic Descriptor Array

 

Pointer Descriptor Array

When a pointerdescriptor is appended to the array, the data it points to is not copied, whichmeans that the pointer descriptor array does NOT take copies, so the descriptorelements must remain in memory for the lifetime of the array, otherwise itreferences invalid information.

General Descriptor Array

General descriptorarray can hold any descriptor type, storing it as a non-modifiable element,i.e., an HBufC copy is created for each descriptor added to the array; thearray itself stores pointers to these copies.

 

TFixedArray vs C++ Array

When working withfixed-length arrays, use TFixedArray instead of C++ array to take advantage ofbounds-checking and the utility functions provided.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值