Why is RBuf is not called HBuf though allocated on heap ?

Login to reply to this topic.
Tue, 2008-07-15 11:45
Joined: 2006-12-19
Forum posts: 72

Hi ,

While trying to find the answer to my question-"If RBuf is something like a modifiable descriptor which is allocated on heap or someting like HBuf, why it is called RBuf ?" - I came across following lines from a document from Symbian Ltd.

1)RBuf descriptors can live on the stack, but maintain a pointer to memory in the heap. On the stack, they take up 8 bytes more than an HBufC* (i.e. 3 words rather than 1), but will generally take up 4 bytes less heap space (if not constructed from an existing BufC).
2)
The new descriptor is not named HBuf because, unlike HBufC, objects of this type are not themselves directly created on the heap (the H prefix stands for heap); choosing an R name carries the implication that the class owns the resources (in this case a Buf) that it manages and is responsible for freeing the memory when it closes.

Now, will somebody help me understand what "On the stack, they take up 8 bytes more than an HBufC* (i.e. 3 words rather than 1), but will generally take up 4 bytes less heap space (if not constructed from an existing BufC) means in a simple manner."

Next, will you tell me what "not themselves directly created on the heap" means and how they are allocated.

Thanks and Regards,
--NN


Tue, 2008-07-15 12:32
Joined: 2008-06-23
Forum posts: 85
Re: Why is RBuf is not called HBuf though allocated on heap ?

Next, will you tell me what "not themselves directly created on the heap" means and how they are allocated.

I think it refers to the fact that the RBuf object, being an R-class, is normally created on the stack, but some of its member variables are allocated on the heap. E.g.:

RBuf8 myBuf;    // "myBuf" allocated on the stack
myBuf.Create(10);  // member variables in myBuf allocated on the heap

Tue, 2008-07-15 16:47
Joined: 2007-09-23
Forum posts: 159
Re: Why is RBuf is not called HBuf though allocated on heap ?

You answered your own question by highlighting the reason in bold.

If somebody asked why is RFs not called HFs because when you use the file system some memory must be being allocated what would be the response? Which is also the answer to your 2nd question. Read about R object to understand about RBuf.

  • Login to reply to this topic.