Thursday, May 05, 2005

6. Large stack-based descriptors

The amount of stack space on Symbian OS is pretty limited (the default is 8 KB). So you should avoid creating large stack-based descriptors when it is unnecessary to do so. Symbian OS sometimes makes it easy to transgress this rule, by defining a number of classes and typedefs that can be used inefficiently on the stack. It pays to be aware of the these and only use them when you know the descriptor you are reading will fill the entire space allocated.

For example, TFileName is typedef-ed as follows:

typedef TBuf<KMaxFileName> TFileName;


const TInt KMaxFileName=0x100; // = 256 decimal

But, of course, each character in a descriptor is 2 bytes, since Symbian OS is a wide, UNICODE, build (as described in 1. The Basics). So each TFileName object created on the stack occupies 512 bytes (1/16th of the default stack size), regardless of whether the text occupying it is actually that long!

Sure, these objects can be very appealing, because they mean you don't have to worry about buffer overrun. But they come at a price.

For stack conservation, it's advisable to be aware of the amount of space the following objects consume:
  • TFileName 512 bytes
  • TEntry 544 bytes
  • TFullName 512 bytes
  • TName 256 bytes
If you do need to use these objects, it's best to use them on the heap. You can do this simply by making them a member of a heap-based object (ie a C class object) . They don't then need to be created on the heap themselves - just by being a member of the C class, they are automatically heap-based. Alternatively, you can alloc them on the heap using the new operator - but make sure they are leave-safe and destroyed when no longer needed.

"For example, TFileName is typedef-ed in e32cmn.h as follows:

typedef TBuf TFileName;"


There seems to be a problem with html tags (they're not allowed?): you may use < and > codes instead:

typedef TBuf <KMaxFileName> TFileName;

You're right, I went through and fixed a lot of these at the weekend, but missed this one - thanks for pointing it out. I've fixed it now.

I've also remove text about the files in which the typedef and KMaxFileName are defined, since this seems to differ according to the release in question.).
If you want to be exact TFileName is actually 520 bytes. 512 for the buffer and 4 bytes for the type and length plus 4 bytes for the max length.
Symbian third party development cost
EVEN by wow gold the standards gold in wowd of the worst financial buy wow gold crisis for at least wow gold cheap a generation, the events of Sunday September 14th and the day before were extraordinary. The weekend began with hopes that a deal could be struck,maplestory mesos with or without government backing, to save Lehman Brothers, America''s fourth-largest investment bank.sell wow gold Early Monday buy maplestory mesos morning Lehman maplestory money filed for Chapter 11 bankruptcy protection. It has more than maplestory power leveling $613 billion of debt.Other vulnerable financial giants scrambled maple money to sell themselves or raise enough capital to stave off a similar fate. billig wow gold Merrill Lynch, the third-biggest investment bank, sold itself to Bank of America (BofA), an erstwhile Lehman suitor,wow power leveling in a $50 billion all-stock power leveling American International Group (AIG) brought forward a potentially life-saving overhaul and went maple story powerleveling cap-in-hand to the Federal Reserve. But its shares also slumped on Monday.
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?

WWW Descriptors FAQ