<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>XieWenjie&#039;s blog &#187; 笔记</title>
	<atom:link href="http://xiewenjie.com/category/notes/feed" rel="self" type="application/rss+xml" />
	<link>http://xiewenjie.com</link>
	<description>Around emacs, linux, etc.</description>
	<lastBuildDate>Sun, 22 May 2011 11:16:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>[设计模式]关于Singleton的回收</title>
		<link>http://xiewenjie.com/2006/01/14/%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f%e5%85%b3%e4%ba%8esingleton%e7%9a%84%e5%9b%9e%e6%94%b6.html</link>
		<comments>http://xiewenjie.com/2006/01/14/%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f%e5%85%b3%e4%ba%8esingleton%e7%9a%84%e5%9b%9e%e6%94%b6.html#comments</comments>
		<pubDate>Sat, 14 Jan 2006 15:16:00 +0000</pubDate>
		<dc:creator>Jay Xie</dc:creator>
				<category><![CDATA[笔记]]></category>

		<guid isPermaLink="false">http://blog.jayxie.com/2006/01/14/%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f%e5%85%b3%e4%ba%8esingleton%e7%9a%84%e5%9b%9e%e6%94%b6</guid>
		<description><![CDATA[
Singleton在不考虑destroy、register、threading safe等的时候很简单，但考虑的时候就复杂了，记录一下今天看的资料以及自己的认识。 写写今天做课程设计的时候设计的一个Platform类时应用的Singleton模式在destroy问题上查阅的一些资料以及自己的想法。汗一下，这么长的句子，呵呵。 Singleton之前在读书笔记里面写的很简单，因为Singleton的确比较容易理解的说，但是实际应用的时候才发现挺多问题的。 在不考虑destroy、register、threading safe的时候，Singleton很容易实现，真的很容易，就是最简单的那个例子，as follows： class Singleton{ public: static Singleton* Instance(); protected: Singleton(); private: static Singleton* _instance; }; Singleton* Singleton::_instance; Singleton* Singleton::Instance(){ if( _instance == 0){ _instance = new Singleton; }; return _instance; } 考虑到注册的时候，就需要一个register以及table还有getInstance时查阅了。这个还是小事。 当考虑到回收的时候，就比较复杂了，网上有这么几种方法，一个是引用，一个是记数。 引用的概念是，对于_instance申明成static Singleton _instance;对于Instance()申明成Singleton &#038; Instance(); 记数的概念就是每次getInstance的时候获取增加一个引用记数，releaseInstance的时候减一个引用记数，根据引用记数来create和destroy，呵呵。 引用的缺陷在于无法很好的控制create和destroy的时机，这个显然并不是我们最想要的，但很简单。而记数的缺陷在于实现的复杂，今天看到的一个例子是用STL里面auto_ptr类，如果再加上考虑线程安全的话，会明显影响效率，呵呵，取舍吧。
]]></description>
			<content:encoded><![CDATA[<p>Singleton在不考虑destroy、register、threading safe等的时候很简单，但考虑的时候就复杂了，记录一下今天看的资料以及自己的认识。<br />
<span id="more-54"></span><br />
写写今天做课程设计的时候设计的一个Platform类时应用的Singleton模式在destroy问题上查阅的一些资料以及自己的想法。汗一下，这么长的句子，呵呵。</p>
<p>Singleton之前在读书笔记里面写的很简单，因为Singleton的确比较容易理解的说，但是实际应用的时候才发现挺多问题的。</p>
<p>在不考虑destroy、register、threading safe的时候，Singleton很容易实现，真的很容易，就是最简单的那个例子，as follows：</p>
<pre class="brush: cpp;">
class Singleton{
public:
    static Singleton* Instance();
protected:
    Singleton();
private:
    static Singleton* _instance;
};

Singleton* Singleton::_instance;
Singleton* Singleton::Instance(){
    if( _instance == 0){
        _instance = new Singleton;
    };
    return _instance;
}
</pre>
<p>考虑到注册的时候，就需要一个register以及table还有getInstance时查阅了。这个还是小事。</p>
<p>当考虑到回收的时候，就比较复杂了，网上有这么几种方法，一个是引用，一个是记数。<br />
引用的概念是，对于_instance申明成static Singleton _instance;对于Instance()申明成Singleton &#038; Instance();<br />
记数的概念就是每次getInstance的时候获取增加一个引用记数，releaseInstance的时候减一个引用记数，根据引用记数来create和destroy，呵呵。</p>
<p>引用的缺陷在于无法很好的控制create和destroy的时机，这个显然并不是我们最想要的，但很简单。而记数的缺陷在于实现的复杂，今天看到的一个例子是用STL里面auto_ptr类，如果再加上考虑线程安全的话，会明显影响效率，呵呵，取舍吧。</p>
]]></content:encoded>
			<wfw:commentRss>http://xiewenjie.com/2006/01/14/%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f%e5%85%b3%e4%ba%8esingleton%e7%9a%84%e5%9b%9e%e6%94%b6.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[设计模式]Singleton</title>
		<link>http://xiewenjie.com/2006/01/07/%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8fsingleton.html</link>
		<comments>http://xiewenjie.com/2006/01/07/%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8fsingleton.html#comments</comments>
		<pubDate>Fri, 06 Jan 2006 16:38:00 +0000</pubDate>
		<dc:creator>Jay Xie</dc:creator>
				<category><![CDATA[笔记]]></category>

		<guid isPermaLink="false">http://blog.jayxie.com/2006/01/07/%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8fsingleton</guid>
		<description><![CDATA[
Singleton通过static关键字和protected的构造函数来确保实例的唯一性。用Static来修饰存储实例的指针，用Static来修饰访问实例的函数，用protected来修饰构造函数。
]]></description>
			<content:encoded><![CDATA[<p>Singleton通过static关键字和protected的构造函数来确保实例的唯一性。用Static来修饰存储实例的指针，用Static来修饰访问实例的函数，用protected来修饰构造函数。<img src="http://blog.csdn.net/xeroo/aggbug/572528.aspx" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://xiewenjie.com/2006/01/07/%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8fsingleton.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[设计模式]Factory Method和Prototype</title>
		<link>http://xiewenjie.com/2006/01/07/%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8ffactory-method%e5%92%8cprototype.html</link>
		<comments>http://xiewenjie.com/2006/01/07/%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8ffactory-method%e5%92%8cprototype.html#comments</comments>
		<pubDate>Fri, 06 Jan 2006 16:34:00 +0000</pubDate>
		<dc:creator>Jay Xie</dc:creator>
				<category><![CDATA[笔记]]></category>

		<guid isPermaLink="false">http://blog.jayxie.com/2006/01/07/%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8ffactory-method%e5%92%8cprototype</guid>
		<description><![CDATA[
Factory Method偏重于讲解静态模式，说一下如何设计符合在编译期能适应多样化产品的工厂方法。Prototype讲的是在面对多样化的产品时，如何利用原型拷贝的概念利用现有对象。
]]></description>
			<content:encoded><![CDATA[<p>Factory Method偏重于讲解静态模式，说一下如何设计符合在编译期能适应多样化产品的工厂方法。Prototype讲的是在面对多样化的产品时，如何利用原型拷贝的概念利用现有对象。<img src="http://blog.csdn.net/xeroo/aggbug/572525.aspx" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://xiewenjie.com/2006/01/07/%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8ffactory-method%e5%92%8cprototype.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[设计模式]Abstract Factory和Builder</title>
		<link>http://xiewenjie.com/2006/01/07/%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8fabstract-factory%e5%92%8cbuilder.html</link>
		<comments>http://xiewenjie.com/2006/01/07/%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8fabstract-factory%e5%92%8cbuilder.html#comments</comments>
		<pubDate>Fri, 06 Jan 2006 16:24:00 +0000</pubDate>
		<dc:creator>Jay Xie</dc:creator>
				<category><![CDATA[笔记]]></category>

		<guid isPermaLink="false">http://blog.jayxie.com/2006/01/07/%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8fabstract-factory%e5%92%8cbuilder</guid>
		<description><![CDATA[
Builder和Abstract Factory的区别有下：Builder是在Director的引导下，一步一步的构建对象；而Abstract Factory则是一次性创建对象。对于Abstract Factory，客户直接操作Factory和Product，所以两者都要抽象出接口；而Builder模式下，Director只操作Builder实例，不直接操作Product，所以Product是什么样，什么接口对于Director压根不关心，自然也就不必抽象出接口咯（其实是因为Product的差异太大，不应该抽象出接口才产生了这个模式的，嘿嘿，为了说区别，偶就反一下啦～大家注意这儿是个错误哦^_^）
]]></description>
			<content:encoded><![CDATA[<p>Builder和Abstract Factory的区别有下：Builder是在Director的引导下，一步一步的构建对象；而Abstract Factory则是一次性创建对象。对于Abstract Factory，客户直接操作Factory和Product，所以两者都要抽象出接口；而Builder模式下，Director只操作Builder实例，不直接操作Product，所以Product是什么样，什么接口对于Director压根不关心，自然也就不必抽象出接口咯（其实是因为Product的差异太大，不应该抽象出接口才产生了这个模式的，嘿嘿，为了说区别，偶就反一下啦～大家注意这儿是个错误哦^_^）<img src="http://blog.csdn.net/xeroo/aggbug/572511.aspx" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://xiewenjie.com/2006/01/07/%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8fabstract-factory%e5%92%8cbuilder.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

