<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to Delete Pointers in Vector or Map in Single Line?</title>
	<atom:link href="http://weseetips.com/2009/03/02/how-to-delete-pointers-in-vector-or-map-in-single-line/feed/" rel="self" type="application/rss+xml" />
	<link>http://weseetips.com/2009/03/02/how-to-delete-pointers-in-vector-or-map-in-single-line/</link>
	<description>Gold mine of Visual C++ tricks!</description>
	<lastBuildDate>Thu, 12 Jan 2012 15:10:53 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: A coder on break.</title>
		<link>http://weseetips.com/2009/03/02/how-to-delete-pointers-in-vector-or-map-in-single-line/comment-page-1/#comment-265</link>
		<dc:creator>A coder on break.</dc:creator>
		<pubDate>Mon, 10 Aug 2009 15:42:14 +0000</pubDate>
		<guid isPermaLink="false">http://weseetips.com/?p=881#comment-265</guid>
		<description>[code]
// move template decl to the method itself.
class DeleteContainerElement
{
    public:
       template void operator()(T* pT){ delete pT; }
};

std::for_each( c.begin(), c.end(), DeleteContainerElement() );
[/code]

With this version you can delete container with raw pointers of any type.</description>
		<content:encoded><![CDATA[<p>[code]<br />
// move template decl to the method itself.<br />
class DeleteContainerElement<br />
{<br />
    public:<br />
       template void operator()(T* pT){ delete pT; }<br />
};</p>
<p>std::for_each( c.begin(), c.end(), DeleteContainerElement() );<br />
[/code]</p>
<p>With this version you can delete container with raw pointers of any type.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jijo.Raj</title>
		<link>http://weseetips.com/2009/03/02/how-to-delete-pointers-in-vector-or-map-in-single-line/comment-page-1/#comment-264</link>
		<dc:creator>Jijo.Raj</dc:creator>
		<pubDate>Mon, 16 Mar 2009 11:39:01 +0000</pubDate>
		<guid isPermaLink="false">http://weseetips.com/?p=881#comment-264</guid>
		<description>Hi Pizer,

Thanks for going through my post and spend time to niggle out the problems.

&gt;&gt; The headers you</description>
		<content:encoded><![CDATA[<p>Hi Pizer,</p>
<p>Thanks for going through my post and spend time to niggle out the problems.</p>
<p>&gt;&gt; The headers you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pizer</title>
		<link>http://weseetips.com/2009/03/02/how-to-delete-pointers-in-vector-or-map-in-single-line/comment-page-1/#comment-263</link>
		<dc:creator>pizer</dc:creator>
		<pubDate>Sun, 15 Mar 2009 20:41:35 +0000</pubDate>
		<guid isPermaLink="false">http://weseetips.com/?p=881#comment-263</guid>
		<description>The headers you&#039;ve included are all standard headers. The conventional way to include those is to use angle brackets.
    You&#039;re kind of suggesting that putting raw pointers in a container that need to be managed is OK. I beg to differ. That&#039;s what smart pointers are for (i.e. tr1::shared_ptr) -- It certainly doesn&#039;t make much sense for string objects but that&#039;s okay becuase it&#039;s just an example.
    The value_type of a map is pair&lt;const key_type, mapped_type&gt; but in your functor you take a pair&lt;key_type, mapped_type&gt; by value which includes copying the key object. Since your functor is generic and the key class might be anything you should accept the map&#039;s value by reference-to-const.


- P</description>
		<content:encoded><![CDATA[<p>The headers you&#8217;ve included are all standard headers. The conventional way to include those is to use angle brackets.<br />
    You&#8217;re kind of suggesting that putting raw pointers in a container that need to be managed is OK. I beg to differ. That&#8217;s what smart pointers are for (i.e. tr1::shared_ptr) &#8212; It certainly doesn&#8217;t make much sense for string objects but that&#8217;s okay becuase it&#8217;s just an example.<br />
    The value_type of a map is pair&lt;const key_type, mapped_type&gt; but in your functor you take a pair&lt;key_type, mapped_type&gt; by value which includes copying the key object. Since your functor is generic and the key class might be anything you should accept the map&#8217;s value by reference-to-const.</p>
<p>- P</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jijo.Raj</title>
		<link>http://weseetips.com/2009/03/02/how-to-delete-pointers-in-vector-or-map-in-single-line/comment-page-1/#comment-262</link>
		<dc:creator>Jijo.Raj</dc:creator>
		<pubDate>Wed, 04 Mar 2009 03:53:49 +0000</pubDate>
		<guid isPermaLink="false">http://weseetips.com/?p=881#comment-262</guid>
		<description>Hi Torin,

Are you sure that you called the delete for each pointer before clearing the list? Or else it will surely leak. In the sample, operator() is calling delete. Well, as a fact MFC itself have a lot of leaks. It will be nice to inspect your code by using NuMega BoundsChecker or Rational Purify or by using some free memory detecting tool like this - http://www.codeproject.com/KB/debug/Memory_leak_finder.aspx

Regards,
Jijo.</description>
		<content:encoded><![CDATA[<p>Hi Torin,</p>
<p>Are you sure that you called the delete for each pointer before clearing the list? Or else it will surely leak. In the sample, operator() is calling delete. Well, as a fact MFC itself have a lot of leaks. It will be nice to inspect your code by using NuMega BoundsChecker or Rational Purify or by using some free memory detecting tool like this &#8211; <a href="http://www.codeproject.com/KB/debug/Memory_leak_finder.aspx" rel="nofollow">http://www.codeproject.com/KB/debug/Memory_leak_finder.aspx</a></p>
<p>Regards,<br />
Jijo.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Torin</title>
		<link>http://weseetips.com/2009/03/02/how-to-delete-pointers-in-vector-or-map-in-single-line/comment-page-1/#comment-261</link>
		<dc:creator>Torin</dc:creator>
		<pubDate>Tue, 03 Mar 2009 10:43:49 +0000</pubDate>
		<guid isPermaLink="false">http://weseetips.com/?p=881#comment-261</guid>
		<description>I don&#039;t know STL. I&#039;m using C++ in general and MFC in specific.

I have problem about memory when deleting one/all/some element from a list/vector. Using the same declaration as above:
  vector StringVector;

I have tried many different way to initialize the list, delete/clear items, but the memory usage of the whole program (as seen by Task Manager) keep increasing. The object(s) in the list are simply &#039;de-linked&#039; but still remain in the memory.

I think your code above will suffer from the same issue. Any idea about this symptom?</description>
		<content:encoded><![CDATA[<p>I don&#8217;t know STL. I&#8217;m using C++ in general and MFC in specific.</p>
<p>I have problem about memory when deleting one/all/some element from a list/vector. Using the same declaration as above:<br />
  vector StringVector;</p>
<p>I have tried many different way to initialize the list, delete/clear items, but the memory usage of the whole program (as seen by Task Manager) keep increasing. The object(s) in the list are simply &#8216;de-linked&#8217; but still remain in the memory.</p>
<p>I think your code above will suffer from the same issue. Any idea about this symptom?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

