which string variable would be a better choice as regards to memory usage?????
| Thu, 2007-09-20 12:31 | |
|
Hi friends, Also, May be the question is a very fundamental one, Waiting for your suggestions With Regards! |
|
| Thu, 2007-09-20 12:31 | |
|
Hi friends, Also, May be the question is a very fundamental one, Waiting for your suggestions With Regards! |
|
Forum posts: 1242
It depends on how many variables you have. If you need only one string, or a few of them, more or less it doesn't matter and you can take whatever you like.
If you need hundreds or even thousands of buffers, the story changes completely.
How many do you need, then?
René Brunner
Forum posts: 1233
I'd like to make you aware of also the nice class RBuf.
It is a new class, encapsulating a lot of the "mess" using normal descriptors, and is often very convenient to use, specially when you have a dynamic amount of dynamic length strings.
Generally, you should avoid putting any strings on the stack in symbian because of limited stack space.
TBuf<> doesn't necessarily mean it is on stack though, if you for example use it as a member variable in a CBase class, it will (ofcourse) end up on the heap when you create your CBase object on the heap.
TPtrC and TPtr doesn't represent any memory, it is just pointers to memory allocated elsewhere (another descriptor, or just a block of memory, either on stack or on heap)
Using TBuf<> will mean you pre-allocate memory, and if your strings are shorter, you will waste the remaining space.
With RBuf you can easily create and realloc exactly as much memory as you need for the string.
Forum posts: 137
hi ,
I used RBuf descriptors;
---------------------------------------------------------------------------------------
I have declared RBuf descriptors in the "xxx .h" file as follows:-
RBuf iFormat_Resolution ;
-----------------------------------------------------------------
In the ".cpp" file i have used it like this:-
TInt separator_indx=SmsBody.Locate(',');
iFormat_Resolution=SmsBody.Left(separator_indx+1);
----------------------------------------------------------------------------------------
Do I require to free the RBuf variables after use?
if yes then
tell me if using "delete iFormat_Resolution" in the destructor of the class will do the job.
OR
should I use some other approach.
With Regards
Sandeep Mohapatra!
Forum posts: 1233
RBuf is an R-class, and follow the same rules as all R-classes.
That is, to free its resources, you have to call Close() on it.
And if you use a temporary one in a function that might leave, you have to call CleanupClosePushL() on it after creating it, so incase of a leave, it will be closed properly.
Forum posts: 137
I am quite confused.
-> I went through the class documentation of RBuf in SDK. It says the HBuf is heap-based. Then I went through another article in the SDK
» Symbian OS v9.2 » Symbian OS guide » Base » Using User Library (E32) » Buffers and Strings » Using Descriptors » How to Use Descriptors » How to use the resizable buffer descriptor RBuf
It says that there is no guarantee that RBuf is created on the heap.It can be on the stack also.
So, I want to know "in what condition is it on the stack"???????????
->also there are three ways to create RBuf from existing buffers:-
A. RBuf.CreateL();---------------------------------//this does not take ownership
B. RBuf.Assign();-----------------------------------//this takes ownership
C.through Assignment operator----------------//no documentation on how to use
->What is the difference between ownership and non-ownership?????????
->Which of the above methods is appropriate for which case????????????
->There is an approach of using RBuf.ReallocL(0) before using RBuf.close()
Is it necessary to change size of RBuf to zero using ReAllocL() before using RBuf.close????????????
Forum posts: 1233
The class "RBuf" itself can live either on heap or the stack as a temporary function variable (like all correctly designed R-classes)
The string it represents, always live on the heap.
the RBuf class hides the allocation and reallocation of it in an easy way.
You should let the class that owns the string keep the actual RBuf object, and to all other functions, you should pass it along as a const TDesC& if it is to be only read, a const TDes& if it is to be changed, and RBuf& only if you need to reallocate it, and never, ever, pass it "by copy".
ownership means the one that is responsible for the strings deallocation in case of error or exit, every object you allocate must have exactly one "owner" that is responsible for the objects destruction.
This is an extremly important concept in symbian, and you should make sure you understand it properly.
Forum posts: 159
When Symbian talk about something being allocated on the stack or the heap they often aren't clear or precise enough for newbies to understand what they mean.
Check out item number 9 in http://www.newlc.com/topic-13580
Forum posts: 1233
Numpy Alert has very good points.
Another thing that helps is to take the time to actually understand what the "heap" and the "stack" is, and how they are used in C++ in generall.
Understanding this, and you will not have to rely on the documentation.
And knowing if something is on the heap or the stack and choosing when to allocate the object where, becomes very easy.
Forum posts: 137
nice article!
I understood some of the things I had confusion in !!!!!
and also came to know about some new things.........
a very nice article indeed.
Thanx ..........
Forum posts: 137
There was another concept that I came across was "folding" and "collation".
This was when I was planning to use "locate()" on "TPtrC".
There were 2 additional functions "LocateReverseF()" and "LocateReverse()"
"LocateReverseF()" --------Searches for the first occurrence of a folded character within this descriptor's folded data
I was confused with what folding is
Then I referred to the article--->
» Symbian OS v9.2 » Symbian OS guide » Base » Using User Library (E32) » Buffers and Strings » Using Descriptors » Descriptor concepts » Folding and collation (comparing strings)
here I was more confused with the language and could not understand anything
some of the terms that created confusion were:-
- normalising text for comparison
- converting accented characters to characters without accents
- tolerant comparisons
- comparisons that are biased towards a match
- locale-independent behaviour
- no guarantee that folding is in any way culturally appropriate
- should not be used for comparing strings in natural language
Then I dropped idea of using "LocateReverseF()"
and used "LocateReverse()" instead.
The statementb in which i used them was
do{---------}
while(XYZ.Locate(',')==XYZ.LocateReverse(','));
But I still wonder if using "locate" for ",'" was right !!!!!!!!!
Forum posts: 2006
Locate() or LocateReverse() are fine to use if you are looking for characters like ',' as in your code above.
Using of Collated/Folded version only make sense if you are dealing with character.
Now imagine you want to locate all 'e' in the following sentence: "HELLO, is déja-vu a french or english word ?"
Depending on the primitive you are using you will match all (E,é,e) or only some of the e letters.
Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant
Forum posts: 137
what I understood:--
--------------------------------
in case of folding
locating "e" in any word will search for all characters that look like "e"
like------
in ur example
--------------------
E -- in --HELLO
e with cap-- in --deja-vu (sorry I could not write the way u have written)
e -- in --french
e -- in --english
Is that right?????????
Forum posts: 1233
Yes, all with the same "base character".
The thing to think of is that this is not correct in all languages.
For example, in swedish the letter "å" is not an "a" with a ring, it is a letter of its own. same with "ö", in swedish, that is not an o with dots on, it is its own letter. (they even have their own keys on my keyboard)
But, CompareF will treat them as the same letter when comparing.
Therefore, CompareF is good for quick and dirty compare, ignoring case and such, but if you want to write a search function that should make sense in all european languages, you need to use CompareC wich is locale dependent.
Forum posts: 137
What does the following lines do?
I have never came across any such thing before....
I cant get any help from sdk also
import e32
e32.start_exe('z:\\system\\programs\\apprun.exe','z:\\system\\apps\\camcorder\\camcorder.app');
What I guess--------
---------------------------
"apprun.exe " -------- is an exe file
"camcorder.app"------is an app file
and
the startexe()
starts the apprun.exe from camcorder.app