<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2718221456176370857</id><updated>2011-11-27T15:49:30.753-08:00</updated><category term='posix thread'/><category term='Virtueware'/><category term='CImageList'/><category term='Array'/><category term='MFC'/><category term='PHP Snippets'/><category term='GDB'/><category term='valgrind'/><category term='Linux'/><category term='memcheck'/><category term='program'/><category term='Mtrace'/><category term='Search Engine'/><category term='semaphore'/><category term='Visual C++'/><category term='Windows'/><category term='SQLite'/><category term='Fun'/><category term='Algorithms'/><category term='cross-platform'/><category term='C++ library'/><title type='text'>Coding Fan</title><subtitle type='html'>Coding,Coding,Coding, Technique Or Art? Fun and Enjoy?</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://codingfan.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://codingfan.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Stars</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>8</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2718221456176370857.post-7302562228139871138</id><published>2007-06-05T09:30:00.000-07:00</published><updated>2007-06-05T09:42:16.792-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Array'/><category scheme='http://www.blogger.com/atom/ns#' term='PHP Snippets'/><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>PHP code Snippets, Algorithms, Array minus</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;There are hundreds of php snippets under the \lib\snippets\ directory of the Zend Studio Installation directory. I document them, write test cases and put them here.&lt;br /&gt;The copyright of these code belongs to the original author. I publish them only for distributation purpose.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;Function:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt;/**&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt; * In this simple function you send two arrays &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt; * and it gives you an array with the operation A-B,  &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt; * elements on A that are not included on B.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt; *&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt; * @param array $vectorA&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt; * @param &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt;array &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt; $vectorB&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt; * @return &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt;array &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt; */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;RestaDeArrays($vectorA,$vectorB)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div style="text-align: left;"&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;        $cantA=count($vectorA);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;    $cantB=count($vectorB);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;    $No_saca=0;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;  &lt;span style="color: rgb(51, 51, 255);"&gt;     for&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;($i=0;$i&lt;$cantA;$i++)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;     {            &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;         for&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;($j=0;$j&lt;$cantB;$j++)         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;        {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;             if($vectorA[$i]==$vectorB[$j])             &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;                $No_saca=1;             &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;        }          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;        if($No_saca==0)         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;            $nuevo_array[]=$vectorA[$i];         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;        else         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;            $No_saca=0;     &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;     &lt;span style="color: rgb(51, 51, 255);"&gt;return &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;$nuevo_array;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153); font-weight: bold;"&gt;Test Code:&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;$vectorA =&lt;/span&gt; &lt;span style="color: rgb(0, 0, 153);"&gt;array&lt;/span&gt;(&lt;span style="color: rgb(255, 0, 0);"&gt;1,2,3,4,5,6,7,8&lt;/span&gt;);&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;$vectorB &lt;/span&gt;= &lt;span style="color: rgb(0, 0, 153);"&gt;array&lt;/span&gt;(&lt;span style="color: rgb(204, 0, 0);"&gt;2,4,6,8,10&lt;/span&gt;);&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;print_r(RestaDeArrays($vectorA,$vectorB));&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153); font-weight: bold;"&gt;output Result:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Array&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;    [0] =&gt; 1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;    [1] =&gt; 3&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;    [2] =&gt; 5&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;    [3] =&gt; 7&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2718221456176370857-7302562228139871138?l=codingfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codingfan.blogspot.com/feeds/7302562228139871138/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2718221456176370857&amp;postID=7302562228139871138' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default/7302562228139871138'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default/7302562228139871138'/><link rel='alternate' type='text/html' href='http://codingfan.blogspot.com/2007/06/php-sinppets-algorithms-array-minus.html' title='PHP code Snippets, Algorithms, Array minus'/><author><name>Stars</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2718221456176370857.post-7914372614820409836</id><published>2007-05-30T08:48:00.000-07:00</published><updated>2007-05-30T09:25:23.070-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++ library'/><category scheme='http://www.blogger.com/atom/ns#' term='cross-platform'/><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><title type='text'>More about simple cross-platform C++ library</title><content type='html'>Last day, I posted that I will publish Chenhua's simple cross-platform C++ library here. Not only copy it character by character, but also modify, extend, test and make some usecases about it.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_XLLDwvI0GGs/Rl2f6LDH-fI/AAAAAAAAABs/2O60HIZ1SEc/s1600-h/Files.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://bp2.blogger.com/_XLLDwvI0GGs/Rl2f6LDH-fI/AAAAAAAAABs/2O60HIZ1SEc/s400/Files.JPG" alt="" id="BLOGGER_PHOTO_ID_5070384577236171250" border="0" /&gt;&lt;/a&gt;   Now, I Compile most of the library successfully. and a list of library is as follows. In the compilation process, I encounter several problems, such as not correct compile command line, precompile header file error  etc.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="font-weight: bold;"&gt;BaseHtmlParser.cpp&lt;/span&gt;  &lt;span style="color: rgb(0, 0, 0);"&gt;Parse HTML Content, Get absolute URL.&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;&lt;span style="font-weight: bold;"&gt;BaseHTTP.cpp  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;A utility class that used to  POST and GET data.&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="font-weight: bold;"&gt;BaseSock.cpp&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;Encapsulate common socket network operations.&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="font-weight: bold;"&gt;Convert.cpp&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;A utility class for &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;cryptography classes. including some functions like Base64 encoding and decoding.&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-weight: bold;"&gt;Des.cpp &lt;/span&gt;Data Encryption Standard encrypt algorithm implementation.&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="font-weight: bold;"&gt;MD5.cpp &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Message Digest hash utility class.&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="font-weight: bold;"&gt;MMutex.cpp&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;Mutex and semaphore operations's cross-platform &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Encapsulation.&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="font-weight: bold;"&gt;Mthread.cpp  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Multi-thread ulitity functions that can be use both in Windows and POSIX systems.&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;&lt;span style="font-weight: bold;"&gt;XML.cpp&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;Implement some simple XML read and write behaviors.&lt;br /&gt;&lt;br /&gt;The following is a Class picture that snapped from Visual Studio.NET IDE( In the Visual C++.NET Perspective and Class View).&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0); font-weight: bold;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.topjoy.net/images/classes.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 665px; height: 595px;" src="http://www.topjoy.net/images/classes.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0); font-weight: bold;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0); font-weight: bold;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 153, 0); font-weight: bold;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0); font-weight: bold;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2718221456176370857-7914372614820409836?l=codingfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codingfan.blogspot.com/feeds/7914372614820409836/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2718221456176370857&amp;postID=7914372614820409836' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default/7914372614820409836'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default/7914372614820409836'/><link rel='alternate' type='text/html' href='http://codingfan.blogspot.com/2007/05/more-about-simple-cross-platform-c.html' title='More about simple cross-platform C++ library'/><author><name>Stars</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp2.blogger.com/_XLLDwvI0GGs/Rl2f6LDH-fI/AAAAAAAAABs/2O60HIZ1SEc/s72-c/Files.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2718221456176370857.post-2674979799016812933</id><published>2007-05-30T03:36:00.000-07:00</published><updated>2007-05-30T03:58:19.194-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQLite'/><category scheme='http://www.blogger.com/atom/ns#' term='Virtueware'/><category scheme='http://www.blogger.com/atom/ns#' term='Search Engine'/><title type='text'>SQLite as virtueware</title><content type='html'>&lt;span style="font-weight: bold;font-size:130%;" &gt;SQLite author's      &lt;/span&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;blessing&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;      The author of  &lt;a href="http://www.sqlite.org/"&gt;SQLite  &lt;/a&gt;disclaims copyright to the source code.  he doesn't place  a legal notice at the header of each source file but  a blessing as follows:&lt;br /&gt;&lt;/span&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-size:130%;"&gt;       May you do good and not evil.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:130%;"&gt;       May you find forgiveness for yourself and forgive others.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:130%;"&gt;       May you share freely, never taking more than you give.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-size:130%;"&gt;How Kindhearted! Some certain humourous and being worth of respect. If every programmer follow these. There may be no cracker again.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Short introduction about SQLite&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;      SQLite is a smart file engine database like Access. Light weight, Fast accessing and many other features.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Search Engine results' comparison&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;      By the way, I saw the sentence &lt;a href="http://www.google.com/search?q=May%20you%20do%20good%20and%20not%20evil&amp;hl=zh-CN&amp;amp;lr=&amp;nxpt=20.694375808574715122209"&gt;"&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;a href="http://www.google.com/search?q=May%20you%20do%20good%20and%20not%20evil&amp;amp;amp;hl=zh-CN&amp;lr=&amp;amp;nxpt=20.694375808574715122209"&gt;May you do good and not evil" &lt;/a&gt;at a first glance, and then think it may be  an idiom from some famous people, even Bible. So&lt;/span&gt;&lt;span style="font-size:130%;"&gt; I search it in Google,  But get a bad result until I add&lt;span style="color: rgb(255, 0, 0);font-size:180%;" &gt; " &lt;/span&gt;before and after the sentence.  and also &lt;a href="http://www.baidu.com/s?wd=May+you+do+good+and+not+evil&amp;cl=3"&gt;baidu.com,  &lt;/a&gt;&lt;br /&gt;But result from&lt;a href="http://www.iask.com/s?tag=n&amp;amp;k=May+you+do+good+and+not+evil"&gt; iAsk.com &lt;/a&gt;is much better than I expected.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2718221456176370857-2674979799016812933?l=codingfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codingfan.blogspot.com/feeds/2674979799016812933/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2718221456176370857&amp;postID=2674979799016812933' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default/2674979799016812933'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default/2674979799016812933'/><link rel='alternate' type='text/html' href='http://codingfan.blogspot.com/2007/05/sqlite-as-virtueware.html' title='SQLite as virtueware'/><author><name>Stars</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2718221456176370857.post-8008604116623154910</id><published>2007-05-29T07:24:00.000-07:00</published><updated>2007-05-29T07:46:15.360-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++ library'/><category scheme='http://www.blogger.com/atom/ns#' term='cross-platform'/><title type='text'>Simple but usefull cross-platform C++ library</title><content type='html'>&lt;span style="font-size:130%;"&gt;       Chenhua, the co-founder of &lt;a href="http://www.kooxoo.com/"&gt;kooxoo.com&lt;/a&gt;, On the 26th, May, 2005, published his cross-platform C++ Library on his blog, &lt;a href="http://dawnli.spaces.live.com/"&gt;http://dawnli.spaces.live.com&lt;/a&gt;. At that time, kooxoo.com has been not found yet(kooxoo.com was started from late 2005, Now it becomes the most famous lifeday search engine in China).&lt;br /&gt;    The library consists of some simple but usefull C++ classes. including socket, multi-thread, cryptography and etc. "Use these classes ,you can develop C++ programs as easy as Java ones", Said Chen.&lt;br /&gt;&lt;br /&gt;     Thanks for his great work. Now I copy most of his code snippets, test and build it into some test programs. Then post here for everyone. The original copyright of the code belongs to Chen.&lt;br /&gt;    Thanks again.&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2718221456176370857-8008604116623154910?l=codingfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codingfan.blogspot.com/feeds/8008604116623154910/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2718221456176370857&amp;postID=8008604116623154910' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default/8008604116623154910'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default/8008604116623154910'/><link rel='alternate' type='text/html' href='http://codingfan.blogspot.com/2007/05/simple-but-usefull-cross-platform-c.html' title='Simple but usefull cross-platform C++ library'/><author><name>Stars</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2718221456176370857.post-8727318849180988546</id><published>2007-05-26T10:37:00.000-07:00</published><updated>2007-05-26T11:08:10.491-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='semaphore'/><category scheme='http://www.blogger.com/atom/ns#' term='GDB'/><category scheme='http://www.blogger.com/atom/ns#' term='posix thread'/><title type='text'>Fix the SEMAPHORE GDB debug bug</title><content type='html'>&lt;p&gt;&lt;span style="font-size:130%;"&gt;When we use gdb to debug posix thread program that use SEMAPHORE machanism. If at the time we debug, there are some threads stop at  &lt;span style="color: rgb(102, 0, 0);"&gt;sem_wait&lt;/span&gt;, when we quit GDB, the condition of&lt;span style="color: rgb(102, 0, 0);"&gt; sem_wait &lt;/span&gt;will become invalid and got some uncertain errors even get the program core dump. As shown in the following sample program:&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p style="color: rgb(102, 0, 204);"&gt;&lt;/p&gt;&lt;p style="color: rgb(102, 0, 204);"&gt;#include &amp;lt;STDIO.H&amp;gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="color: rgb(102, 0, 204);"&gt;#include &amp;lt;ERRNO.H&amp;gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="color: rgb(102, 0, 204);"&gt;#include &amp;lt;PTHREAD.H&amp;gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="color: rgb(102, 0, 204);"&gt;#include&amp;lt;SEMAPHORE.H&amp;gt;&lt;/p&gt; &lt;p style="color: rgb(102, 0, 204);"&gt;&lt;span style="font-size:130%;"&gt; sem_t empty; &lt;/span&gt;&lt;/p&gt; &lt;p style="color: rgb(102, 0, 204);"&gt;&lt;span style="font-size:130%;"&gt;sem_t full; &lt;/span&gt;&lt;/p&gt; &lt;p style="color: rgb(102, 0, 204);"&gt;&lt;span style="font-size:130%;"&gt;int value[1]; &lt;/span&gt;&lt;/p&gt; &lt;p style="color: rgb(102, 0, 204);"&gt;&lt;span style="font-size:130%;"&gt;void * child1(void *arg)&lt;/span&gt;&lt;/p&gt; &lt;p style="color: rgb(102, 0, 204);"&gt;&lt;span style="font-size:130%;"&gt; { &lt;/span&gt;&lt;/p&gt; &lt;p style="color: rgb(102, 0, 204);"&gt;&lt;span style="font-size:130%;"&gt;       int i = 0; &lt;/span&gt;&lt;/p&gt; &lt;p style="color: rgb(102, 0, 204);"&gt;&lt;span style="font-size:130%;"&gt;       int ret = 0;&lt;/span&gt;&lt;/p&gt; &lt;p style="color: rgb(102, 0, 204);"&gt;&lt;span style="font-size:130%;"&gt;        pthread_t tid=pthread_self();&lt;/span&gt;&lt;/p&gt; &lt;p style="color: rgb(102, 0, 204);"&gt;&lt;span style="font-size:130%;"&gt; for(;;)&lt;br /&gt;{&lt;br /&gt;value[0]=i++;&lt;br /&gt;printf("thread %d set value : %d\n",tid, value[0]);&lt;br /&gt;ret = sem_post(&amp;full);&lt;br /&gt;if(ret)&lt;br /&gt;printf("thread %d sem_post full fail: %d \n", tid, ret);&lt;br /&gt;sleep(5);&lt;br /&gt;if(0 != (ret = sem_wait(&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&amp;amp;empty&lt;/span&gt;)&lt;span style="font-size:130%;"&gt;)))&lt;br /&gt;{&lt;br /&gt;  printf ("Sem_wait returned %ld\n", (unsigned long)ret);&lt;br /&gt; printf("sem_wait for handler failed"); exit(1);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;void * child2(void *arg)&lt;br /&gt;{&lt;br /&gt;pthread_t tid=pthread_self();&lt;br /&gt;int ret = 0;&lt;br /&gt;for(;;)&lt;br /&gt;{&lt;br /&gt;     if(0 != (ret = sem_wait(&amp;full)))&lt;br /&gt;   {&lt;br /&gt;           printf ("Sem_wait returned %ld\n", (unsigned long)ret);&lt;br /&gt;            printf("sem_wait for handler failed");&lt;br /&gt;             exit(1);&lt;br /&gt;   }&lt;br /&gt;    printf("thread %d get value %d\n",tid, value[0]);&lt;br /&gt;    value[0]=0;&lt;br /&gt;     ret = sem_post(&amp;amp;empty&lt;/span&gt;);&lt;br /&gt;&lt;/p&gt;&lt;p style="color: rgb(102, 0, 204);"&gt;&lt;span style="font-size:130%;"&gt;     if(ret)&lt;br /&gt;      printf("thread %d sem_post empty fail:%d\n", tid, ret); sleep(1);&lt;br /&gt;         }&lt;br /&gt;  }&lt;br /&gt;int main(void)&lt;br /&gt;{&lt;br /&gt;   pthread_t tid1,tid2;&lt;br /&gt;  sem_init (&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&amp;amp;empty&lt;/span&gt;)&lt;span style="font-size:130%;"&gt;, 0, 0);&lt;br /&gt;    sem_init (&amp;full, 0, 0);&lt;br /&gt;   printf("hello\n");&lt;br /&gt;   value[0]=0;&lt;br /&gt;    pthread_create(&amp;tid1,NULL,child1,NULL);&lt;br /&gt; pthread_create(&amp;tid2,NULL,child2,NULL);&lt;br /&gt;sleep(1000);&lt;br /&gt; printf("main thread exit\n");&lt;br /&gt;      return 0;&lt;br /&gt;   }&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;In this sample program. if when we debug it use GDB, Thread 2 wait at   After the GDB process terminated. &lt;span style="color: rgb(102, 0, 0); font-weight: bold;"&gt;sem_wait,sem_wait&lt;/span&gt; will return  a non-zero value &lt;/span&gt;&lt;span style="font-size:130%;"&gt;automatically&lt;/span&gt;&lt;span style="font-size:130%;"&gt;. But it is not what we want to see, because it should wait.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;Why? Can it be fixed? The answer is yes. the quit of GDB will got a interupt signal &lt;span style="color: rgb(102, 0, 0);"&gt;EINTR&lt;/span&gt;, you can check the global variable &lt;span style="color: rgb(153, 0, 0);font-size:180%;" &gt;errno &lt;/span&gt;whether equals &lt;span style="color: rgb(153, 51, 0);"&gt;EINTR&lt;/span&gt;, if this is , we ignore the signal and wait again. if not, another error emerges. I exit  the program explictly, you can also call &lt;span style="color: rgb(102, 0, 0); font-weight: bold;"&gt;assert(0)&lt;/span&gt; to get the program core dump and then debug it.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;code patch of the program shows as following:&lt;br /&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;b&gt;if(0 != (ret = sem_wait(&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&amp;amp;empty&lt;/span&gt;)&lt;span style="font-size:130%;"&gt;&lt;b&gt;)))&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;b&gt; {&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;b&gt;             printf ("Sem_wait returned %ld\n", (unsigned long)ret);&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;b&gt;             printf("sem_wait for handler failed"); exit(1);&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt; &lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;b&gt;改成:&lt;/b&gt;&lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt;while (0 != (ret = sem_wait(&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&amp;amp;empty&lt;/span&gt;)&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt;)))&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt;           if (errno != EINTR)&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt;            {&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt;                    printf ("Sem_wait returned %ld\n", (unsigned long)ret); printf("sem_wait for handler failed"); exit(1);&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt;             }&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt; }&lt;/b&gt;&lt;/span&gt; &lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:130%;"&gt;将 &lt;b&gt;if(0 != (ret = sem_wait(&amp;full)))&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;b&gt; {&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;b&gt;              printf ("Sem_wait returned %ld\n", (unsigned long)ret);&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;b&gt;              printf("sem_wait for handler failed");&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;b&gt;              exit(1);&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;b&gt;} &lt;/b&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:130%;"&gt;&lt;b&gt;改成:&lt;/b&gt;&lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt;while (0 != (ret = sem_wait(&amp;full)))&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt;              if (errno != EINTR)&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt;             {&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt;                  printf ("Sem_wait returned %ld\n", (unsigned long)ret);&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt;                  printf("sem_wait for handler failed");&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt;                  exit(1);&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt;             }&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style=";font-size:130%;color:red;"  &gt;&lt;b&gt; }&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt; &lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2718221456176370857-8727318849180988546?l=codingfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codingfan.blogspot.com/feeds/8727318849180988546/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2718221456176370857&amp;postID=8727318849180988546' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default/8727318849180988546'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default/8727318849180988546'/><link rel='alternate' type='text/html' href='http://codingfan.blogspot.com/2007/05/fix-semaphore-gdb-debug-bug.html' title='Fix the SEMAPHORE GDB debug bug'/><author><name>Stars</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2718221456176370857.post-374460964098792707</id><published>2007-05-26T10:22:00.000-07:00</published><updated>2007-05-26T10:34:58.913-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><category scheme='http://www.blogger.com/atom/ns#' term='MFC'/><category scheme='http://www.blogger.com/atom/ns#' term='CImageList'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual C++'/><title type='text'>Extracting Single Images from a CImageList object in MFC</title><content type='html'>&lt;span style="font-weight: bold;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-size:130%;" name="intelliTxt" id="intelliTXT" &gt;&lt;p nd="7"&gt;Here is the function:&lt;/p&gt; &lt;p nd="8"&gt;It takes 3 parameters, and returns nothing.&lt;/p&gt; &lt;ul&gt;&lt;li nd="10"&gt;&lt;code style="color: rgb(153, 0, 0);" nd="9"&gt;lstImages&lt;/code&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;: &lt;/span&gt;A pointer to the &lt;code style="color: rgb(153, 0, 0);" nd="11"&gt;CImageList&lt;/code&gt;&lt;span style="color: rgb(153, 0, 0);"&gt; &lt;/span&gt;object containing all of the images.  &lt;/li&gt;&lt;li nd="13"&gt;&lt;code style="color: rgb(153, 51, 0);" nd="12"&gt;nImage&lt;/code&gt;&lt;span style="color: rgb(153, 51, 0);"&gt;:&lt;/span&gt; The index of the image that is going to be extracted.  &lt;/li&gt;&lt;li nd="15"&gt;&lt;code style="color: rgb(153, 0, 0);" nd="14"&gt;destBitmap&lt;/code&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;: &lt;/span&gt;A pointer to the &lt;code style="color: rgb(102, 0, 0);" nd="16"&gt;CBitmap&lt;/code&gt; object that is going to contain the extracted image.&lt;/li&gt;&lt;/ul&gt; &lt;p nd="17"&gt;The function makes a copy of the image list, and moves the requested image to the front of that list.&lt;/p&gt; &lt;p nd="18"&gt;It then draws the requested image into the destination bitmap.&lt;/p&gt;&lt;div class="smallText" id="premain0" style="width: 100%;"&gt;&lt;span nd="19" preid="0" style="margin-bottom: 0pt;" id="precollapse0"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre nd="20" style="margin-top: 0pt; color: rgb(0, 0, 0);" id="pre0"&gt;&lt;span class="cpp-keyword"&gt;void&lt;/span&gt; CMyWindowClass::GetImageFromList(CImageList *lstImages,&lt;br /&gt;                         &lt;span class="cpp-keyword"&gt;int&lt;/span&gt; nImage, CBitmap* destBitmap)&lt;br /&gt;{&lt;br /&gt; &lt;span style="color: rgb(0, 102, 0);" class="cpp-comment"&gt;//First we want to create a temporary image list we can manipulate&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;    &lt;/span&gt;CImageList tmpList;&lt;br /&gt; tmpList.Create(lstImages);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);" class="cpp-comment"&gt;//Then swap the requested image to the first spot in the list &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;   &lt;/span&gt;tmpList.Copy( &lt;span class="cpp-literal"&gt;0&lt;/span&gt;, nImage, ILCF_SWAP );&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);" class="cpp-comment"&gt;//Now we need to get som information about the image &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;   &lt;/span&gt;IMAGEINFO lastImage;&lt;br /&gt;tmpList.GetImageInfo(&lt;span class="cpp-literal"&gt;0&lt;/span&gt;,&amp;lastImage);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);" class="cpp-comment"&gt;//Heres where it gets fun&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;   &lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);" class="cpp-comment"&gt;//Create a Compatible Device Context using &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;   &lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);" class="cpp-comment"&gt;//the valid DC of your calling window&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;   &lt;/span&gt;CDC dcMem; dcMem.CreateCompatibleDC (GetWindowDC());&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);" class="cpp-comment"&gt;//This rect simply stored the size of the image we need&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;  &lt;/span&gt; CRect rect (lastImage.rcImage);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);" class="cpp-comment"&gt;//Using the bitmap passed in, Create a bitmap &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;   &lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);" class="cpp-comment"&gt;//compatible with the window DC&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;   &lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);" class="cpp-comment"&gt;//We also know that the bitmap needs to be a certain size.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;  &lt;/span&gt; destBitmap-&gt;CreateCompatibleBitmap (&lt;span class="cpp-keyword"&gt;this&lt;/span&gt;-&gt;GetWindowDC(),&lt;br /&gt;                                  rect.Width (), rect.Height ());&lt;br /&gt;&lt;br /&gt;&lt;span class="cpp-comment"&gt;//Select the new destination bitmap into the DC we created above&lt;/span&gt;&lt;br /&gt;CBitmap* pBmpOld = dcMem.SelectObject (destBitmap);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);" class="cpp-comment"&gt;//This call apparently "draws" the bitmap from the list, &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;   &lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);" class="cpp-comment"&gt;//onto the new destination bitmap&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;  &lt;/span&gt; tmpList.DrawIndirect (&amp;dcMem, &lt;span class="cpp-literal"&gt;0&lt;/span&gt;, CPoint (&lt;span class="cpp-literal"&gt;0&lt;/span&gt;, &lt;span class="cpp-literal"&gt;0&lt;/span&gt;),&lt;br /&gt;       CSize (rect.Width (), rect.Height ()), CPoint (&lt;span class="cpp-literal"&gt;0&lt;/span&gt;, &lt;span class="cpp-literal"&gt;0&lt;/span&gt;));&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);" class="cpp-comment"&gt;//cleanup by reselecting the old bitmap object into the DC&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;  &lt;/span&gt; dcMem.SelectObject (pBmpOld);&lt;br /&gt;}&lt;/pre&gt; &lt;p nd="21"&gt;It looks big, but remove the comments and you have a mere 12 lines of code.&lt;/p&gt;&lt;p nd="21"&gt;you can call the function above use two lines of code like following:&lt;br /&gt;&lt;/p&gt;&lt;/span&gt;&lt;span name="intelliTxt" id="intelliTXT"  style="font-size:130%;"&gt;&lt;span style="color: rgb(102, 0, 204);"&gt;CBitmap bitMap;&lt;br /&gt;&lt;br /&gt;GetImageFromList(&amp;m_ImageListSrc, extractIndex, &amp;amp;amp;amp;bitMap);&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-size:130%;" name="intelliTxt" id="intelliTXT" &gt;&lt;br /&gt;&lt;br /&gt;Then you can do what you like with the variable bitMap;&lt;br /&gt;&lt;br /&gt;The original URL of the solution is:http://www.codeproject.com/bitmap/getimagefromlist.asp&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2718221456176370857-374460964098792707?l=codingfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codingfan.blogspot.com/feeds/374460964098792707/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2718221456176370857&amp;postID=374460964098792707' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default/374460964098792707'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default/374460964098792707'/><link rel='alternate' type='text/html' href='http://codingfan.blogspot.com/2007/05/extracting-single-images-from.html' title='Extracting Single Images from a CImageList object in MFC'/><author><name>Stars</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2718221456176370857.post-3926286493201146475</id><published>2007-04-26T07:47:00.000-07:00</published><updated>2007-04-26T08:07:43.517-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Mtrace'/><category scheme='http://www.blogger.com/atom/ns#' term='Fun'/><title type='text'>Just for fun</title><content type='html'>&lt;span style="font-size:130%;"&gt;I search some thing about "mtrace" in Google, I click the url below and then ....&lt;br /&gt;&lt;br /&gt;&lt;a href="http://linux.about.com/library/cmd/blcmdl3_mtrace.htm"&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;http://linux.about.com/library/cmd/blcmdl3_mtrace.htm&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;=&gt;&lt;br /&gt;&lt;a href="http://servedby.advertising.com/click/site=0000716263/mnum=0000428382/genr=1/tkdt=B0P0R1T0/cstr=38601465=_4630bdd0,5214848944,716263%5E428382%5E-1%5E0,1_/bnum=38601465"&gt;http://servedby.advertising.com/click/&lt;/a&gt;&lt;br /&gt;&lt;a href="http://servedby.advertising.com/click/site=0000716263/mnum=0000428382/genr=1/tkdt=B0P0R1T0/cstr=38601465=_4630bdd0,5214848944,716263%5E428382%5E-1%5E0,1_/bnum=38601465"&gt;site=0000716263/mnum=0000428382/genr=1/&lt;/a&gt;&lt;br /&gt;&lt;a href="http://servedby.advertising.com/click/site=0000716263/mnum=0000428382/genr=1/tkdt=B0P0R1T0/cstr=38601465=_4630bdd0,5214848944,716263%5E428382%5E-1%5E0,1_/bnum=38601465"&gt;tkdt=B0P0R1T0/cstr=38601465=_4630bdd0,5214848944&lt;/a&gt;&lt;br /&gt;&lt;a href="http://servedby.advertising.com/click/site=0000716263/mnum=0000428382/genr=1/tkdt=B0P0R1T0/cstr=38601465=_4630bdd0,5214848944,716263%5E428382%5E-1%5E0,1_/bnum=38601465"&gt;,716263%5E428382%5E-1%5E0,1_/bnum=38601465&lt;/a&gt;&lt;br /&gt;=&gt;&lt;br /&gt;&lt;a href="http://www.usafis.org/_sys/EN/count_land3_en.asp?af=add_cht"&gt;http://www.usafis.org/_sys/EN/count_land3_en.asp?af=add_cht&lt;/a&gt;&lt;br /&gt;=&gt;&lt;br /&gt;Select "I am married"&lt;br /&gt;=&gt;&lt;br /&gt;A dialog opened, And Then I click "Chat"....&lt;br /&gt;Fun?&lt;br /&gt;&lt;br /&gt;Chat Information     Please wait for a site operator to respond.&lt;br /&gt;Chat Information     Hello, my name is Daniel. I am a USAFIS organization representative. I am here to help you to register you for the American Green Card program.&lt;br /&gt;Daniel: Are you interested in living and working in USA?&lt;br /&gt;you: yes.&lt;br /&gt;Daniel: Now, before we can proceed i need to check your eligibility for the Green Card lottery, ok?&lt;br /&gt;Daniel: Which country were you born in?&lt;br /&gt;you: No problem.I just want to learn something about in America.I am born in China.&lt;br /&gt;Daniel: Which country were your parents born in?&lt;br /&gt;Daniel: Which country was your wife/husband born in?&lt;br /&gt;you: They are all born in China.&lt;br /&gt;Daniel: I am sorry, but you are not eligible for the Green Card Lottery because you were born in a non-eligible country. This is the rule of the U.S. State Department.&lt;br /&gt;Chat InformationChat session has been terminated by the site operator&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2718221456176370857-3926286493201146475?l=codingfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codingfan.blogspot.com/feeds/3926286493201146475/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2718221456176370857&amp;postID=3926286493201146475' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default/3926286493201146475'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default/3926286493201146475'/><link rel='alternate' type='text/html' href='http://codingfan.blogspot.com/2007/04/just-for-fun.html' title='Just for fun'/><author><name>Stars</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2718221456176370857.post-4684869572466130169</id><published>2007-04-26T07:27:00.000-07:00</published><updated>2007-04-26T08:22:00.842-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='valgrind'/><category scheme='http://www.blogger.com/atom/ns#' term='program'/><category scheme='http://www.blogger.com/atom/ns#' term='memcheck'/><title type='text'>Program Tools Serias: Part 1.Valgrind</title><content type='html'>&lt;h2 class="title"&gt;Short Introduction And usage of &lt;a href="http://www.valgrind.org/"&gt;Valgrind&lt;/a&gt;(From Valgrind official site)&lt;br /&gt;&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;Valgrind is an  award-winning  suite of tools for debugging and profiling Linux programs. With the tools that come with Valgrind, you can automatically detect many memory management and threading bugs, avoiding hours of frustrating bug-hunting, making your programs more stable. You can also perform detailed profiling, to speed up and reduce memory use of your programs.&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:130%;"&gt;The Valgrind distribution currently includes four tools: a memory error detector, a cache (time) profiler, a call-graph profiler, and a heap (space) profiler.  It runs on the following platforms: X86/Linux, AMD64/Linux, PPC32/Linux, PPC64/Linux.&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:130%;"&gt;Valgrind is &lt;a href="http://www.opensource.org/"&gt;Open Source&lt;/a&gt; /  &lt;a href="http://www.gnu.org/philosophy/free-sw.html"&gt;Free Software&lt;/a&gt;, and is freely available under the  &lt;a href="http://www.gnu.org/licenses/gpl.html"&gt;GNU General Public License&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;&lt;div&gt;&lt;h2 class="title" style="clear: both;"&gt;&lt;a name="quick-start.intro"&gt;&lt;/a&gt;1. Introduction&lt;/h2&gt;&lt;/div&gt;&lt;div class="sect1" lang="en"&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;The Valgrind distribution has multiple tools.  The most popular is the memory checking tool (called Memcheck) which can detect many common memory errors such as:&lt;/span&gt;&lt;/p&gt; &lt;div class="itemizedlist"&gt;&lt;ul type="disc"&gt;&lt;li&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;touching memory you shouldn't (eg. overrunning heap block     boundaries);&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;using values before they have been initialized;&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;incorrect freeing of memory, such as double-freeing heap     blocks;&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;memory leaks.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;What follows is the minimum information you need to start detecting memory errors in your program with Memcheck.  Note that this guide applies to Valgrind version 2.4.0 and later; some of the information is not quite right for earlier versions.&lt;/span&gt;&lt;/p&gt; &lt;/div&gt; &lt;div class="sect1" lang="en"&gt; &lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h2 class="title" style="clear: both;"&gt; &lt;a name="quick-start.prepare"&gt;&lt;/a&gt;2. Preparing your program&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;Compile your program with &lt;code class="option"&gt;-g&lt;/code&gt; to include debugging information so that Memcheck's error messages include exact line numbers.  Using &lt;code class="computeroutput"&gt;-O0&lt;/code&gt; is also a good idea, if you can tolerate the slowdown.  With &lt;code class="computeroutput"&gt;-O1&lt;/code&gt; line numbers in error messages can be inaccurate, although generally speaking Memchecking code compiled at &lt;code class="computeroutput"&gt;-O1&lt;/code&gt; works fairly well.  Use of &lt;code class="computeroutput"&gt;-O2&lt;/code&gt; and above is not recommended as Memcheck occasionally reports uninitialised-value errors which don't really exist.&lt;/span&gt;&lt;/p&gt; &lt;/div&gt; &lt;div class="sect1" lang="en"&gt; &lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h2 class="title" style="clear: both;"&gt; &lt;a name="quick-start.mcrun"&gt;&lt;/a&gt;3. Running your program under Memcheck&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;If you normally run your program like this: &lt;/span&gt;&lt;/p&gt; &lt;pre class="programlisting"&gt;&lt;span style="font-size:130%;"&gt;    &lt;span style="color: rgb(0, 153, 0);"&gt;myprog arg1 arg2&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;  Use this command line: &lt;/span&gt;&lt;/p&gt; &lt;pre class="programlisting"&gt;&lt;span style="font-size:130%;"&gt;    &lt;span style="color: rgb(0, 153, 0);"&gt;valgrind --leak-check=yes myprog arg1 arg2&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;  Memcheck is the default tool.  The &lt;code class="option"&gt;--leak-check&lt;/code&gt; option turns on the detailed memory leak detector.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;Your program will run much slower (eg. 20 to 30 times) than normal, and use a lot more memory.  Memcheck will issue messages about memory errors and leaks that it detects.&lt;/span&gt;&lt;/p&gt; &lt;/div&gt; &lt;div class="sect1" lang="en"&gt; &lt;div class="titlepage"&gt;&lt;div&gt;&lt;div&gt;&lt;h2 class="title" style="clear: both;"&gt; &lt;a name="quick-start.interpret"&gt;&lt;/a&gt;4. Interpreting Memcheck's output&lt;/h2&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;Here's an example C program with a memory error and a memory leak.  &lt;/span&gt;&lt;/p&gt; &lt;pre class="programlisting"&gt;&lt;span style="color: rgb(0, 153, 0);font-size:130%;" &gt;#include&lt;stdlib.h&gt;&lt;/stdlib.h&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;stdlib.h&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;void f(void)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   int* x = malloc(10 * sizeof(int));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   x[10] = 0;        // problem 1: heap block overrun&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;}                    // problem 2: memory leak -- x not freed&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;int main(void)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   f();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;   return 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/stdlib.h&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;  Most error messages look like the following, which describes problem 1, the heap block overrun:  &lt;/span&gt;&lt;/p&gt; &lt;pre class="programlisting"&gt;&lt;span style="color: rgb(0, 153, 0);font-size:130%;" &gt;==19182== Invalid write of size 4&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:130%;" &gt;==19182==    at 0x804838F: f (example.c:6)&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:130%;" &gt;==19182==    by 0x80483AB: main (example.c:11)&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:130%;" &gt;==19182==  Address 0x1BA45050 is 0 bytes after a block of size 40 alloc'd&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:130%;" &gt;==19182==    at 0x1B8FF5CD: malloc (vg_replace_malloc.c:130)&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:130%;" &gt;==19182==    by 0x8048385: f (example.c:5)&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:130%;" &gt;==19182==    by 0x80483AB: main (example.c:11)&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;  Things to notice:  &lt;/span&gt;&lt;/p&gt; &lt;div class="itemizedlist"&gt;&lt;ul type="disc"&gt;&lt;li&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;There is a lot of information in each error message; read it    carefully.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;The 19182 is the process ID;  it's usually unimportant.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;The first line ("Invalid write...") tells you what kind of    error it is.  Here, the program wrote to some memory it should not    have due to a heap block overrun.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;Below the first line is a stack trace telling you where the     problem occurred.  Stack traces can get quite large, and be     confusing, especially if you are using the C++ STL.  Reading them     from the bottom up can help.  If the stack trace is not big enough,     use the &lt;code class="option"&gt;--num-callers&lt;/code&gt; option to make it     bigger.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;The code addresses (eg. 0x804838F) are usually unimportant, but    occasionally crucial for tracking down weirder bugs.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;Some error messages have a second component which describes     the memory address involved.  This one shows that the written memory     is just past the end of a block allocated with malloc() on line 5 of     example.c.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;  It's worth fixing errors in the order they are reported, as later errors can be caused by earlier errors.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;Memory leak messages look like this:  &lt;/span&gt;&lt;/p&gt; &lt;pre class="programlisting"&gt;&lt;span style="color: rgb(0, 153, 0);font-size:130%;" &gt;==19182== 40 bytes in 1 blocks are definitely lost in loss record 1 of 1&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:130%;" &gt;==19182==    at 0x1B8FF5CD: malloc (vg_replace_malloc.c:130)&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:130%;" &gt;==19182==    by 0x8048385: f (a.c:5)&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-size:130%;" &gt;==19182==    by 0x80483AB: main (a.c:11)&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;  The stack trace tells you where the leaked memory was allocated. Memcheck cannot tell you why the memory leaked, unfortunately.  (Ignore the "vg_replace_malloc.c", that's an implementation detail.)&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:130%;"&gt;There are several kinds of leaks; the two most important categories are:  &lt;/span&gt;&lt;/p&gt; &lt;div class="itemizedlist"&gt;&lt;ul type="disc"&gt;&lt;li&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;"definitely lost": your program is leaking memory -- fix     it!&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style="font-size:130%;"&gt;"probably lost": your program is leaking memory, unless you're     doing funny things with pointers (such as moving them to point to     the middle of a heap block).&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold; color: rgb(204, 0, 0);"&gt;PS: Valgrind is my favourite memory leak check tool.  I got a lot from it.&lt;br /&gt;By the way, my most use option of valgrind is :&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;--leak-check=full --show-reachable=yes&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2718221456176370857-4684869572466130169?l=codingfan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codingfan.blogspot.com/feeds/4684869572466130169/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2718221456176370857&amp;postID=4684869572466130169' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default/4684869572466130169'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2718221456176370857/posts/default/4684869572466130169'/><link rel='alternate' type='text/html' href='http://codingfan.blogspot.com/2007/04/program-tools-serias-1valgrind.html' title='Program Tools Serias: Part 1.Valgrind'/><author><name>Stars</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
