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;
where
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:
For example, TFileName is typedef-ed as follows:
typedef TBuf<KMaxFileName>
where
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
Comments:
<< Home
"For example, TFileName is typedef-ed in e32cmn.h as follows:
typedef TBuf TFileName;"
Jo,
There seems to be a problem with html tags (they're not allowed?): you may use < and > codes instead:
typedef TBuf <KMaxFileName> TFileName;
David.-
typedef TBuf TFileName;"
Jo,
There seems to be a problem with html tags (they're not allowed?): you may use < and > codes instead:
typedef TBuf <KMaxFileName> TFileName;
David.-
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.).
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.
Post a Comment
<< Home