How to use CDescArray
Login to reply to this topic.
Fri, 2006-08-18 06:48
Joined: 2006-08-12
Forum posts: 7
 :?Hi I am new in Symbian So I want to know about CDescArray by an Example.Pls Help me as soon as possible.

C programmers never die.They are just cast into void.


Fri, 2006-08-18 08:07
Joined: 2006-04-28
Forum posts: 84
Hi Mr. Sinha

     This is how I have used CDesCArrayFlat in my applications. If you want something specification, then mention that in you post.

//Declaration

CDesCArrayFlat* Carray;   

Carray =new (ELeave) CDesCArrayFlat(1);
Carray->Reset();//reseting the array

_LIT(formats,"%S");
value1.Format(formats,&ch);//ch is the value to be added

Carray->AppendL(value1);//adding value to the array


Carray->Delete(2);//will delete the value at index 2

Hope this helps. You can always go to SDK help to check all this and more.

Cheers!!!

Nitin Sahdev
Symbian Developer

Mon, 2006-08-21 14:55
Joined: 2005-03-14
Forum posts: 59
Quote from: sahdev_nitin
Carray =new (ELeave) CDesCArrayFlat(1);

You should in real live use bigger value than 1. This is a 'granularity' - how much array gets increased when required. Setting it to one makes not much sense - array will get increased every time you add something.
Tue, 2006-08-22 04:59
Joined: 2006-04-28
Forum posts: 84
Hi Kaisub,

    Thanks for the explanation. Hope this helps Mr. Sinha too. I have used this as an example code and the granularity of one doesn't hinder any processing or so, you are right that everytime when we add an element then the array will increase by one, then thats what I want to do, and moreover it doesn't add any overheads to the processing. I have tried it with diff values, as documented it raises E32USER-CBase 18 panic if we provide  negative value.

Cheers!!!

Nitin Sahdev
Symbian Developer

Tue, 2006-08-22 07:27
Joined: 2005-11-20
Forum posts: 1321
Quote
and moreover it doesn't add any overheads to the processing.

No, that's not true.

An example: You add 10000 entries to an array, in a loop, one after the other. With a granularity of 1 this means that the system de-allocates the old array and allocates a new one 10000 times as well. Allocates are pretty fast, but of course the system also must copy the array content so far from the old array to the new, bigger array.

With a granularity of e.g. 100 there would be 100 times less allocates and copies.

Of course the granularity hardly makes a difference with an array of 10 elements or so, and that's probably the reason why you did not notice any difference, but my example shows that with large arrays a granularity of 1 does add considerable and unneccessary overhead.

René Brunner

Tue, 2006-08-22 11:11
Joined: 2006-04-28
Forum posts: 84
Hi Rbrunner

    It might be the fact as I have used the code for a value of abt 150. It didn't made any significant difference in my application's processing times.
    Thnx for clearing my concepts.

Cheers!!!

Nitin Sahdev
Symbian Developer


copyright 2003-2009 NewLC SARL