<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>_crtisvalidheappointer &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/_crtisvalidheappointer/</link>
	<description>Feed of posts on WordPress.com tagged "_crtisvalidheappointer"</description>
	<pubDate>Wed, 30 Dec 2009 22:31:06 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[How to check whether the Pointer is allocated in Stack or Heap in Debug?]]></title>
<link>http://weseetips.com/2008/12/14/how-to-check-whether-the-pointer-is-allocated-in-stack-or-heap-in-debug/</link>
<pubDate>Sun, 14 Dec 2008 18:06:55 +0000</pubDate>
<dc:creator>Jijo.Raj</dc:creator>
<guid>http://weseetips.com/2008/12/14/how-to-check-whether-the-pointer-is-allocated-in-stack-or-heap-in-debug/</guid>
<description><![CDATA[What if you call delete operator by using a stack pointer? Like that, while writing frameworks somet]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.wordpress.com/files/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
What if you call delete operator by using a stack pointer? Like that, while writing frameworks sometimes we expects the pointer that gets passed to the function should point a valid memory block which is allocated on heap itself. So <span style="color:#0000ff;">how can we check whether the pointer points to stack or heap in debug version</span>?</p>
<p><img class="alignnone size-full wp-image-703" title="stackorheap" src="http://weseetips.wordpress.com/files/2008/12/stackorheap.jpg" alt="stackorheap" width="479" height="284" /></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.wordpress.com/files/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
You can use the function &#8211; <span style="color:#0000ff;">_CrtIsValidHeapPointer()</span>. Its an undocumented CRT function. But it <strong><span style="color:#0000ff;">works only in debug version</span></strong>. Well, please check the code snippet below,</p>
<pre>#include "malloc.h"
...

// Check heap pointer.
int* pInteger = new int;
BOOL bHeap = _CrtIsValidHeapPointer( pInteger );

// Check stack pointer and you'll get an assertion.
char CharArray[100];
bHeap = _CrtIsValidHeapPointer( CharArray );</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.wordpress.com/files/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Its annoying that its not available in release version. Well, atleast we could make our framework to notify the user while debugging in the debug build. isn&#8217;t it?</p>
<p><img class="alignnone size-medium wp-image-51" title="beginnerseries" src="http://weseetips.wordpress.com/files/2008/03/beginnerseries.jpg?w=215" alt="" width="215" height="32" /><br />
Targeted Audience &#8211; Beginners.</p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
