RArray of TBuf as parameter
Login to reply to this topic.
ven, 2007-05-25 23:14
Joined: 2007-01-24
Forum posts: 10
I need to pass as parameter to a function an array of strings, I tried
func(RArray<TBuf<100>> buf) but did not compile properly. Then I tried func(RArray<TDesc> buf) but I did not know how to pass the parameter to the function (I did: RArray<TDesC>* iParam;
   iParam->Append(_L("Param"));
   iParam->Append(_L("Param2"));
   RArray< TBuf<100> > iBuc = func(iParam); but in the function I did not have the corrects values). I supposed is something related to pointers but I did not know how to continue. Thanks in advance.

dim, 2007-05-27 00:32
Joined: 2006-09-18
Forum posts: 68
Hi, the reason RArray<TBuf<100>> buf doesn't compile properly is because you are basically specifying a shif operator and the compiler will expect a number followed by 2 >
Rather do this
RArray< TBuf<100> > buf
check the spaces "> >" instead of  ">>" that should compile.

RArray needs to have fixed sized members, so RArray<TDesC> buf won't work,TDesC descriptors can be any maximum length.

RArray<TDesC>* iParam; could work, but the _L() macro returns a TPtrC, this is not a pointer, but a class containing a pointer and the descriptor length.

I would suggest if you want variable length descrptors in your array, look at SDK docs
CPtrCArray
CDesCArrayFlat
CDesCArraySeg
If you have a lot of TBuf<100>'s and performance is vital then use the first approach.
lun, 2007-05-28 06:30
Joined: 2006-07-17
Forum posts: 4
Hi,
Use RArray<TPtrC> rather than TDesC. It works perfectly.

RArray<TPtrC> values;
TPtrC valptr;
TBuf<100> buf = _L("aaaaaaaaaaaaaa");
valptr.Set(buf);
values.Append(valptr);

try it
Vikas
mauj telcom
lun, 2007-05-28 12:37
Joined: 2006-09-18
Forum posts: 68
Hi vikasv

That will work, but why not use the Descriptor array's provided by Symbian?
The only reason I sugested RArray< TBuf<100> > might be used, was purely for performance reasons as RArray's are quicker that CArray's

I'm not an expert, but I think that TPtrCs are slower to acces than a TBuf<> thereby decreasing the performance gain, and if you have to do conversions, performance really goes downhill. A real expert might point us in the right direction here.

Therfore I would suggest using
CPtrCArray for PtrCs
the
CDesCArrayxxx
have the advantage that it owns the descriptor, so it is easy to delete the descriptors.

check out the SDK documentation "Symbian OS v9.1 » Symbian OS guide » System libraries » Using BAFL » Descriptor Arrays"

PS: about the performance, I could be horribly wrong, I just thought of the fact that there would typically be less to copy to the array if you only need to copy the pointer and length ie. a TPtrC
lun, 2007-05-28 12:40
Joined: 2003-12-05
Forum posts: 822
Quote from: vikasv
Hi,
Use RArray<TPtrC> rather than TDesC. It works perfectly.

RArray<TPtrC> values;
TPtrC valptr;
TBuf<100> buf = _L("aaaaaaaaaaaaaa");
valptr.Set(buf);
values.Append(valptr);

try it
Vikas
mauj telcom

Yes, try it and see what happens when the descriptor the TPtrC is pointing to gets out of scope...

void func(RArray<TBufC<100> > & aArray) should do the trick (with the spaces as already mentioned). Remember also that there is a size limit to the objects you put on the RArray. This is documented in the SDK. And you cannot put TDes/C objects into a RArray, since they are abstract classes.

copyright 2003-2009 NewLC SARL