You Are Here:

Community: Blogs

Paul Todd's Forum Nokia Blog

Use and abuse of Symbian idioms

Paul.Todd | 02 April, 2007 23:18

I saw a very interesting snipped of code on the newsgroups the other day. It showed how people can so easily misuse Symbian programming idioms if they are not careful

    RArray<TInt>* array = new (ELeave) RArray<TInt>;
    array->Append(1);
    array->Append(2);
    delete array;

This is not the original class, the original class used another R class but the problem is still the same.
To all intents and purposes this look like safe c++ code but the coder failed to realize that an RClose MUST be closed and cannot be deleted.

I wonder how many other people have been bitten by this issue?

RSSComments

Re: Use and abuse of Symbian idioms

TwmD | 06/06/2007, 15:44

RClasses as an idiom work quite well for real resources or references to objects owned by other threads. But are pretty confusing when used as datastructures.

The general rule of R classes is that you should never "new" them since it should be possible to copy R classes by value. As an example and RString is a handle to a real string owned by an RStringPool object - so copying the RString would mean copying just the handle and not the whole string.
However, there are many exceptions to this rule in Symbian OS.

Here is where it gets confusing:

If you have RArray<TInt> a;
a.Append(12);
RArray<TInt> b= a;
a.Close()
RDebug::Print("%D",b[1]); <---- Does this work?

Is b still a valid copy? I.e was the RArray contents reference counted.

In my view Symbian should have used R classes only for things which derive from RHandleBase and have a clear policy for duplication and sharing accross threads and processes.
Other classes which use R prefix are usually just proxy/pimpl objects.

Another one to watch out for is:
RPointerArray - You must call ResetAndDestroy() before the call to Close() if you want all the objects delete. Close() only deletes the memory allocated to the container.

Re: Use and abuse of Symbian idioms

jplauril | 06/06/2007, 16:50

/me raises hand.

I fixed a bug like this from my code just five minutes ago :)
You must login to post comments. Login
 

Rate This

 
 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxHiE2cE20IE27mE20PaulE2cE20butE20youE20canE20alsoE20callE20meE20ToddE20andE20IE20wonE27tE20getE20upsetE2eE20PaulE2eToddE20E7cE2002E20AprilE2cE202007E2023E3a18E20IE20sawE20aE20veryE20interestingE20snippedE20ofE20codeE20onE20theE20newsgroupsE20theE20otherE20dayE2eE20ItE20showedE20howE20peopleE20canE20soE20easilyE20misuseE20SymbianE20programmingE20idiomsE20ifE20theyE20areE20notE20carefulEa0Ea0Ea0E20E52ArrayE3cTIntE3eE2aE20arrayE20E3dE20newE20E28E45E4ceaveE29E20E52ArrayE3cTIntE3eE3bEa0Ea0Ea0E20arrayE2dE3eAppendE281E29E3bEa0Ea0Ea0E20arrayE2dE3eAppendE282E29E3bEa0Ea0Ea0E20deleteE20arrayE3bThisE20isE20notE20theE20originalE20classE2cE20theE20originalE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fblogsE2eforumE2enokiaE2ecomE2fblogE2fpaulE2dtoddsE2dforumE2dnokiaE2dblogE2f2007E2f04E2f02E2fuseE2dandE2dabuseE2dofE2dsymbianE2didiomsX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxPaulE20ToddE27sE20ForumE20NokiaE20BlogE20E7cE20UseE20andE20abuseE20ofE20SymbianE20idiomsX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZBlogContentQ qdcZtypeQUqfntypeZBlogE45ntryQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxHiE2cE20IE27mE20PaulE2cE20butE20youE20canE20alsoE20callE20meE20ToddE20andE20IE20wonE27tE20getE20upsetE2eE20PaulE2eToddE20E7cE2002E20AprilE2cE202007E2023E3a18E20IE20sawE20aE20veryE20interestingE20snippedE20ofE20codeE20onE20theE20newsgroupsE20theE20otherE20dayE2eE20ItE20showedE20howE20peopleE20canE20soE20easilyE20misuseE20SymbianE20programmingE20idiomsE20ifE20theyE20areE20notE20carefulEa0Ea0Ea0E20E52ArrayE3cTIntE3eE2aE20arrayE20E3dE20newE20E28E45E4ceaveE29E20E52ArrayE3cTIntE3eE3bEa0Ea0Ea0E20arrayE2dE3eAppendE281E29E3bEa0Ea0Ea0E20arrayE2dE3eAppendE282E29E3bEa0Ea0Ea0E20deleteE20arrayE3bThisE20isE20notE20theE20originalE20classE2cE20theE20originalE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fblogsE2eforumE2enokiaE2ecomE2fX qfnZtopicQUqfnTopicZcppQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZseriesE5f60QRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZseriesE5f80QRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtypeQUqfntypeZBlogContentQ qfnZtypeQUqfntypeZBlogE45ntryQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZupdatedQDx2007E2d06E2d06X qfnZuserE5ftagQSxs60X qfnZuserE5ftagQSxseriesE2d80X qfnZuserE5ftagQSxsymbianE2dcE2bE2bX qmarsZdescriptionQSxHiE2cE20IE27mE20PaulE2cE20butE20youE20canE20alsoE20callE20meE20ToddE20andE20IE20wonE27tE20getE20upsetE2eE20PaulE2eToddE20E7cE2002E20AprilE2cE202007E2023E3a18E20IE20sawE20aE20veryE20interestingE20snippedE20ofE20codeE20onE20theE20newsgroupsE20theE20otherE20dayE2eE20ItE20showedE20howE20peopleE20canE20soE20easilyE20misuseE20SymbianE20programmingE20idiomsE20ifE20theyE20areE20notE20carefulEa0Ea0Ea0E20E52ArrayE3cTIntE3eE2aE20arrayE20E3dE20newE20E28E45E4ceaveE29E20E52ArrayE3cTIntE3eE3bEa0Ea0Ea0E20arrayE2dE3eAppendE281E29E3bEa0Ea0Ea0E20arrayE2dE3eAppendE282E29E3bEa0Ea0Ea0E20deleteE20arrayE3bThisE20isE20notE20theE20originalE20classE2cE20theE20originalE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZBlogContentQ qrdfZtypeQUqfntypeZBlogE45ntryQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ