<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.newlc.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>NewLC - There is a question about HBufC* on the ReAlloc() memory allocation - Comments</title>
 <link>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation</link>
 <description>Comments for &quot;There is a question about HBufC* on the ReAlloc() memory allocation&quot;</description>
 <language>en</language>
<item>
 <title>Re: There is a question</title>
 <link>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation#comment-41717</link>
 <description>&lt;p&gt; &lt;img src=&quot;/sites/all/modules/smileys/packs/example/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt; &lt;br /&gt;
Hah,&lt;br /&gt;
Right,&lt;/p&gt;

&lt;p&gt;Cheers,&lt;br /&gt;
huang&lt;/p&gt;</description>
 <pubDate>Sat, 22 Sep 2007 04:45:43 +0200</pubDate>
 <dc:creator>huangfangcheng</dc:creator>
 <guid isPermaLink="false">comment 41717 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: There is a question about HBufC* on the ReAlloc()</title>
 <link>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation#comment-41697</link>
 <description>&lt;p&gt;Check out this pdf &lt;a href=&quot;http://developer.symbian.com/main/downloads/papers/RBuf/Introduction_to_RBuf_v1.0.pdf&quot;&gt;http://developer.symbian.com/main/downloads/papers/RBuf/Introduction_to_RBuf_v1.0.pdf&lt;/a&gt;. It says &quot;RBuf descriptors were introduced in Symbian OS v9 and backported to v8.1 and v8.0&quot;&lt;/p&gt;

&lt;p&gt;Cheers,&lt;br /&gt;
Sri&lt;/p&gt;</description>
 <pubDate>Fri, 21 Sep 2007 11:14:07 +0200</pubDate>
 <dc:creator>srikanth</dc:creator>
 <guid isPermaLink="false">comment 41697 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: There is a question about</title>
 <link>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation#comment-41689</link>
 <description>&lt;p&gt;Hi all:&lt;/p&gt;

&lt;p&gt;Yes ,I remember had a documentation  file (.PDF) pressed by Symbian, specialized explain aboud RBuf.&lt;br /&gt;
RBuf derivatived dircted By TDes.But as I know ,Series 60 2nd SDK did&#039;t support RBuf.&lt;br /&gt;
&lt;/p&gt;</description>
 <pubDate>Fri, 21 Sep 2007 09:11:20 +0200</pubDate>
 <dc:creator>huangfangcheng</dc:creator>
 <guid isPermaLink="false">comment 41689 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: There is a question about HBufC* on the ReAlloc() memory...</title>
 <link>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation#comment-41638</link>
 <description>&lt;p&gt;Hey guys, it is an interesting topic. ReAlloc is often misunderstood (and hence, misused). &lt;br /&gt;
@ huangfangcheng: Have you tried RBuf yet? RBufs are the most useful descriptors for these scenarios. Also, if all the HBufC*s do is hold literals, probably you can work with just TPtrC. But I presume that the code is just for illustration.&lt;/p&gt;</description>
 <pubDate>Thu, 20 Sep 2007 08:20:44 +0200</pubDate>
 <dc:creator>guru_k</dc:creator>
 <guid isPermaLink="false">comment 41638 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: There is a question about HBufC*</title>
 <link>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation#comment-41634</link>
 <description>&lt;p&gt;My tool is CodeWarrior 5.5.3.1604&lt;/p&gt;</description>
 <pubDate>Thu, 20 Sep 2007 07:32:19 +0200</pubDate>
 <dc:creator>mickeyfirst</dc:creator>
 <guid isPermaLink="false">comment 41634 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: There is</title>
 <link>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation#comment-41600</link>
 <description>&lt;p&gt; &lt;img src=&quot;/sites/all/modules/smileys/packs/example/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt; &lt;br /&gt;
AT Fructose:&lt;br /&gt;
Thanks Very much.&lt;br /&gt;
That is right!&lt;br /&gt;
In your help, I have modified my code to ensure its accuracy!&lt;/p&gt;</description>
 <pubDate>Wed, 19 Sep 2007 06:06:58 +0200</pubDate>
 <dc:creator>huangfangcheng</dc:creator>
 <guid isPermaLink="false">comment 41600 at http://www.newlc.com</guid>
</item>
<item>
 <title>on the ReAlloc() memory allocation</title>
 <link>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation#comment-41598</link>
 <description>&lt;p&gt;You do need to pop HBufs off the cleanupstack and repush them.  &lt;/p&gt;

&lt;p&gt;Also the code in&lt;br /&gt;
&lt;a href=&quot;http://descriptors.blogspot.com/2005/05/20-how-do-i-use-heap-based-buffer.html&quot;&gt;http://descriptors.blogspot.com/2005/05/20-how-do-i-use-heap-based-buffer.html&lt;/a&gt;&lt;br /&gt;
is incorrect.&lt;/p&gt;

&lt;p&gt;The following code will panic if the cell is moved:&lt;/p&gt;

&lt;p&gt;HBufC* buf = .....&lt;br /&gt;
CleanupStack::PushL(buf);&lt;br /&gt;
buf = buf-&gt;ReAllocL(5000);&lt;br /&gt;
CleanupStack::PopAndDestroy(buf);&lt;/p&gt;

&lt;p&gt;After the realloc it should be:&lt;br /&gt;
CleanupStack::Pop();&lt;br /&gt;
CleanupStack::PushL(buf);&lt;br /&gt;
.....&lt;br /&gt;
CleanupStack::PopAndDestory(buf);&lt;/p&gt;

&lt;p&gt;Try it for yourself and see, you can try and force the call to ReAlloc() to move the memory by preceeding it with a call to something like &lt;br /&gt;
TUint* scrap = (TUint*) User::Alloc(5000);&lt;/p&gt;

&lt;p&gt;If you want to understand descriptors read the chapter on them in &lt;br /&gt;
&lt;a href=&quot;http://www.amazon.co.uk/Symbian-OS-Mobile-Phones-Press/dp/0470066415/ref=sr_1_1/203-1802158-8469513?ie=UTF8&amp;s=books&amp;qid=1190141073&amp;sr=1-1&quot;&gt;http://www.amazon.co.uk/Symbian-OS-Mobile-Phones-Press/dp/0470066415/ref=sr_1_1/203-1802158-8469513?ie=UTF8&amp;s=books&amp;qid=1190141073&amp;sr=1-1&lt;/a&gt;&lt;/p&gt;</description>
 <pubDate>Tue, 18 Sep 2007 20:44:51 +0200</pubDate>
 <dc:creator>Fructose</dc:creator>
 <guid isPermaLink="false">comment 41598 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: There is a question about HBufC*</title>
 <link>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation#comment-41562</link>
 <description>&lt;p&gt; &lt;img src=&quot;/sites/all/modules/smileys/packs/example/evil.png&quot; title=&quot;Evil&quot; alt=&quot;Evil&quot; /&gt; &lt;br /&gt;
At mickyfirst --&lt;br /&gt;
i&#039;m sorry ,still or error!&lt;br /&gt;
Did you debug in VC6.0 sp6 environment ?&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;HBufC* newBuffer = myHeapDes-&amp;gt;ReAllocL(KString2().Length());&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::Pop(myHeapDes);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::PushL(newBuffer);&amp;nbsp; //NOTICE: don&amp;#039;t forget to call&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //CleanupStack::Pop(newBuffer) at appropiate line&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Replace entire string in the HBufC&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *newBuffer = KString2;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console-&amp;gt;Printf(KFromat1,newBuffer,newBuffer-&amp;gt;Length());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::PopAndDestroy(newBuffer);&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
as your code ,BUT it is WRONG!&lt;br /&gt;
maybe it is the address of myHeapDes when it call ReAllocL() is changed ,rbrunner is correct,it return a correct address,and we need to store it!&lt;/p&gt;</description>
 <pubDate>Tue, 18 Sep 2007 05:16:56 +0200</pubDate>
 <dc:creator>huangfangcheng</dc:creator>
 <guid isPermaLink="false">comment 41562 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: There is a question</title>
 <link>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation#comment-41558</link>
 <description>&lt;p&gt;Hi huangfangcheng&lt;/p&gt;

&lt;p&gt;I consider your method is same as mine. &lt;/p&gt;

&lt;p&gt;when you test my codes , maybe you did not modify &lt;code&gt;*myHeapDes = KString2;&lt;/code&gt; as &lt;code&gt;*newBuffer = KString2;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Because the root cause of your problem is: when calling ReAllocL, the below steps will excute&lt;/p&gt;

&lt;p&gt;1. creating a new heap descriptor.&lt;/p&gt;

&lt;p&gt;2. copying the original data into the new descriptor.&lt;/p&gt;

&lt;p&gt;3. deleting the original descriptor.&lt;/p&gt;

&lt;p&gt;Br/Yin&lt;/p&gt;</description>
 <pubDate>Tue, 18 Sep 2007 03:34:46 +0200</pubDate>
 <dc:creator>mickeyfirst</dc:creator>
 <guid isPermaLink="false">comment 41558 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: There is a question about HBufC*</title>
 <link>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation#comment-41552</link>
 <description>&lt;p&gt;I got it,&lt;br /&gt;
like that it&#039;s OK!&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;myHeapDes = myHeapDes-&amp;gt;ReAllocL(KString2().Length());//if you do not do this,next line would panic&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Replace entire string in the HBufC&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *myHeapDes = KString2;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console-&amp;gt;Printf(KFromat1,myHeapDes,myHeapDes-&amp;gt;Length());&lt;br /&gt;&lt;br /&gt;Thanks&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;</description>
 <pubDate>Mon, 17 Sep 2007 16:28:01 +0200</pubDate>
 <dc:creator>huangfangcheng</dc:creator>
 <guid isPermaLink="false">comment 41552 at http://www.newlc.com</guid>
</item>
<item>
 <title>Descriptor FAQ</title>
 <link>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation#comment-41547</link>
 <description>&lt;p&gt;I can recommend the &quot;Descriptor FAQ&quot; at&lt;br /&gt;
&lt;a href=&quot;http://descriptors.blogspot.com/2005/05/20-how-do-i-use-heap-based-buffer.html&quot; class=&quot;bb-url&quot;&gt;http://descriptors.blogspot.com/2005/05/20-how-do-i-use-heap-based-buffer.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At huangfangcheng: ReAllocL can&#039;t possibly lead to waste of memory, because the old memory is freed, regardless of what you do with the new pointer.&lt;/p&gt;

&lt;p&gt;I think the only problem with your original code is the fact that you don&#039;t store the return value of ReAllocL, as this return value is the (possibly) new pointer to the re-allocated HBufC, and without that of course it does not work.&lt;/p&gt;

&lt;p&gt;At mickeyfirst: I dont&#039; think that the CleanupStack is a problem when working with ReAllocL. I think that the CleanupStack does not store the pointer to the allocated memory, but a pointer to (i.e. the address of) myHeapDes itself. Check the sample code in the Descriptor FAQ using ReAllocL: There is no Pop/Re-PushL there...&lt;br /&gt;
&lt;/p&gt;</description>
 <pubDate>Mon, 17 Sep 2007 14:44:03 +0200</pubDate>
 <dc:creator>rbrunner</dc:creator>
 <guid isPermaLink="false">comment 41547 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: There is a question</title>
 <link>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation#comment-41540</link>
 <description>&lt;p&gt;To mickeyfirst:&lt;br /&gt;
Sorry ,it is still or erroneous,I tried you method.&lt;br /&gt;
i think if you allocate a new object (HBufC* newBuffer) ,maybe it is waste memory,&lt;br /&gt;
THANKS very much! &lt;br /&gt;
&lt;/p&gt;</description>
 <pubDate>Mon, 17 Sep 2007 13:10:23 +0200</pubDate>
 <dc:creator>huangfangcheng</dc:creator>
 <guid isPermaLink="false">comment 41540 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: There is a question</title>
 <link>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation#comment-41523</link>
 <description>&lt;p&gt;not painc at the point of &quot; myHeapDes-&gt;ReAllocL&quot;, but at  the line, &quot;*myHeapDes = KString2;&quot;&lt;/p&gt;

&lt;p&gt;modify &lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;myHeapDes-&amp;gt;ReAllocL(KString2().Length());&amp;nbsp; &lt;br /&gt;//Replace entire string in the HBufC&lt;br /&gt;*myHeapDes = KString2;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;as belowing&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;HBufC* newBuffer = myHeapDes-&amp;gt;ReAllocL(KString2().Length());&amp;nbsp; &lt;br /&gt;CleanupStack::Pop(myHeapDes);&lt;br /&gt;CleanupStack::)PushL(newBuffer);&amp;nbsp; //&lt;span style=&quot;font-weight:bold&quot;&gt;NOTICE: don&amp;#039;t forget to call CleanupStack::Pop(newBuffer) at appropiate line&lt;/span&gt;&lt;br /&gt;//Replace entire string in the HBufC&lt;br /&gt;*newBuffer = KString2;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;</description>
 <pubDate>Mon, 17 Sep 2007 08:58:40 +0200</pubDate>
 <dc:creator>mickeyfirst</dc:creator>
 <guid isPermaLink="false">comment 41523 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: There is a question about HBufC*</title>
 <link>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation#comment-41521</link>
 <description>&lt;p&gt;What is the panic code? Other thing what you have to do is after myHeapDes-&gt;ReAllocL you have to pop and push myHeapDes in to cleanupstack as the address might have changed.&lt;/p&gt;

&lt;p&gt;Cheers,&lt;br /&gt;
Sri&lt;/p&gt;</description>
 <pubDate>Mon, 17 Sep 2007 08:36:42 +0200</pubDate>
 <dc:creator>srikanth</dc:creator>
 <guid isPermaLink="false">comment 41521 at http://www.newlc.com</guid>
</item>
<item>
 <title>There is a question about HBufC* on the ReAlloc() memory allocation</title>
 <link>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation</link>
 <description>&lt;p&gt;The source is :&lt;/p&gt;

&lt;p&gt;CConsoleBase* console;&lt;br /&gt;
_LIT(KString1,&quot;HBufC_test&quot;);&lt;br /&gt;
//#define _LIT(name,s) const HLitC&lt;sizeof(s)&gt; name = {sizeof(s)-1,s}&lt;br /&gt;
_LIT(KString2,&quot;My Heap String&quot;);&lt;br /&gt;
_LIT(KName,&quot;HBufC_test&quot;);&lt;/p&gt;

&lt;p&gt;void RunConsoleL()&lt;br /&gt;
{&lt;br /&gt;
	HBufC* myHeapDes = HBufC::NewL(KString1().Length());&lt;br /&gt;
	CleanupStack::PushL(myHeapDes);&lt;br /&gt;
	*myHeapDes = KString1;&lt;br /&gt;
	&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://www.newlc.com/en/forum/there-question-about-hbufc-realloc-memory-allocation#comments</comments>
 <category domain="http://www.newlc.com/en/forums/symbian-c">Symbian C++</category>
 <pubDate>Mon, 17 Sep 2007 06:15:20 +0200</pubDate>
 <dc:creator>huangfangcheng</dc:creator>
 <guid isPermaLink="false">18989 at http://www.newlc.com</guid>
</item>
</channel>
</rss>
