<?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>神秘果 &#187; 程序设计</title>
	<atom:link href="http://www.shenmiguo.com/cat/program/feed" rel="self" type="application/rss+xml" />
	<link>http://www.shenmiguo.com</link>
	<description>There&#039;re Miracles When You Believe.</description>
	<lastBuildDate>Wed, 07 Apr 2010 03:46:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Coredump设置</title>
		<link>http://www.shenmiguo.com/archives/2010/327_coredump.html</link>
		<comments>http://www.shenmiguo.com/archives/2010/327_coredump.html#comments</comments>
		<pubDate>Wed, 07 Apr 2010 03:46:43 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[coredump]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=327</guid>
		<description><![CDATA[Linux下当程序crash时，会产生core文件，记录程序非正常退出时的内存映象，通过gdb可以加载core文件可调试跟踪程序出错的代码所在行。 配置coredump Coredump的设置和2个文件相关。在/proc/sys/kernel目录下： /proc/sys/kernel/core_pattern文件设置core文件的保存路径和文件名称，pattern可使用参数： %p &#8211; insert pid into filename %u &#8211; insert current uid into filename %g &#8211; insert current gid into filename %s &#8211; insert signal that caused the coredump into the filename %t &#8211; insert UNIX time that the coredump occurred into filename %h &#8211; insert hostname where the coredump happened into [...]]]></description>
			<content:encoded><![CDATA[<p><span class="Apple-style-span" style="line-height: 15px; ">Linux<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">下当程序</span>crash<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时，会产生</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件，记录程序非正常退出时的内存映象，通过</span>gdb<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">可以加载</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件可调试跟踪程序出错的代码所在行。</span></span></p>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span id="more-327"></span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><b><span style="font-size:12.0pt;line-height:125%;font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">配置</span></b><b><span style="font-size:12.0pt;<br />
line-height:125%">coredump</span></b></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%">Coredump<span style="font-family:<br />
宋体;Times New Roman&quot;;Times New Roman&quot;">的设置和</span>2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个文件相关。在</span>/proc/sys/kernel<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">目录下：</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span style="color:red">/proc/sys/kernel/core_pattern</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件设置</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件的保存路径和文件名称，</span>pattern<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">可使用参数：</span></div>
<div style="margin-top:0cm;margin-right:0cm;margin-bottom:3.0pt;<br />
margin-left:21.0pt;line-height:125%">%p &#8211; insert pid into filename</div>
<div style="margin-top:0cm;margin-right:0cm;margin-bottom:3.0pt;<br />
margin-left:21.0pt;line-height:125%">%u &#8211; insert current uid into filename</div>
<div style="margin-top:0cm;margin-right:0cm;margin-bottom:3.0pt;<br />
margin-left:21.0pt;line-height:125%">%g &#8211; insert current gid into filename</div>
<div style="margin-top:0cm;margin-right:0cm;margin-bottom:3.0pt;<br />
margin-left:21.0pt;line-height:125%">%s &#8211; insert signal that caused the coredump into the filename</div>
<div style="margin-top:0cm;margin-right:0cm;margin-bottom:3.0pt;<br />
margin-left:21.0pt;line-height:125%">%t &#8211; insert UNIX time that the coredump occurred into filename</div>
<div style="margin-top:0cm;margin-right:0cm;margin-bottom:3.0pt;<br />
margin-left:21.0pt;line-height:125%">%h &#8211; insert hostname where the coredump happened into filename</div>
<div style="margin-top:0cm;margin-right:0cm;margin-bottom:3.0pt;<br />
margin-left:21.0pt;line-height:125%">%e &#8211; insert coredumping executable name into filename</div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如：</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;/data/coredump/core_%e_%t&quot; &gt; /proc/sys/kernel/core_pattern</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%">core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件统一在</span>/data/coredump<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">目录下产生，格式为</span>core_<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">进程名</span>_<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时间戳</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%">/proc/sys/kernel/core_pattern<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中的默认内容是</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，表示</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件生成在可执行程序所在目录，文件名叫</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。新的</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">就会覆盖旧的</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件。</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span style="color:red">/proc/sys/kernel/core_users_pid</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">控制</span>core<span style="font-family:<br />
宋体;Times New Roman&quot;;Times New Roman&quot;">文件是否加</span>pid<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">作为</span>core_pattern<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中约定文件名称的扩展名。表示添加</span>pid<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">作为扩展名，生成的</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件格式为</span>core.xxxx<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；为</span>0<span style="font-family:<br />
宋体;Times New Roman&quot;;Times New Roman&quot;">则表示生成的</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件同一命名为</span>core_pattern<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。该文件内容默认值是</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如：</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &#39;1&#39; &gt; /proc/sys/kernel/core_uses_pid</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">再加上</span>core_pattern <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的设置，</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件统一在</span>/data/coredump<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">目录下产生，格式为</span>core_<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">进程名</span>_<span style="font-family:<br />
宋体;Times New Roman&quot;;Times New Roman&quot;">时间戳</span>.<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">进程号</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%">&nbsp;</div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><b><span style="font-size:12.0pt;line-height:125%">Core</span></b><b><span style="font-size:12.0pt;line-height:125%;font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件开关</span></b></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">使用</span>ulimit -c<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">查看</span>core<span style="font-family:<br />
宋体;Times New Roman&quot;;Times New Roman&quot;">文件生成开关。若为</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">则表示不会生成</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件。</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">使用</span>ulimit -c size<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">设置</span>core<span style="font-family:<br />
宋体;Times New Roman&quot;;Times New Roman&quot;">文件的大小限制，</span>size<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的单位是</span>kbyte<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。若要想</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件大小不受限制，则使用</span>ulimit -c unlimited</div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">有了</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件。使用</span>gdb<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">加载调试：</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gdb &ndash;c core</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件名</span> <span style="font-family:<br />
宋体;Times New Roman&quot;;Times New Roman&quot;">可执行程序名</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2010/327_coredump.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Base64编码原理</title>
		<link>http://www.shenmiguo.com/archives/2010/326_base64-encode.html</link>
		<comments>http://www.shenmiguo.com/archives/2010/326_base64-encode.html#comments</comments>
		<pubDate>Sun, 28 Feb 2010 04:14:16 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[base64 编码]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=326</guid>
		<description><![CDATA[定义 Base64是用64个可见字符表示任意字节编码方式。 Base64在RFC2045的section 6.8（The Base64 Content-Transfer-Encoding is designed to represent arbitrary sequences of octets in a form that need not be humanly readable）定义：Base64内容传送编码被设计用来把任意序列的8位字节描述为一种不易被人直接识别的形式。 相对于Base64，还有Base16、Base32编码方式，可以参见RFC3548（The Base16, Base32, and Base64 Data Encodings）。 Base64编码应用：电子邮件编码传输、广告点击跳转加密编码串、Cookie串二进制内容编码。 &#160; 编码范围 一个字节的编码范围是[0x00, 0xff]，共8个位，256个字符（可称为一个八位组或Base256）。 Base64的编码范围是[0x00, 0x3f]，共6个位，64个字符（也为一个六位组）。 Base64的编码过程就是把八位组变成六位组的过程，每三个8bit的字节转换为四个6bit的字节（3*8 = 4*6 = 24），然后把6bit再添两位高位0，组成四个8bit的字节。也就是说，转换后的字符串理论上要比原来的长1/3（3字节编码成4字节）。 Base64使用的映射字符： 编码 字符 编码 字符 编码 字符 编码 字符 0 A 17 R [...]]]></description>
			<content:encoded><![CDATA[<p><b><span style="font-size: 12pt; line-height: 125%; font-family: 宋体;">定义</span></b></p>
<div style="margin-bottom: 3.9pt; line-height: 125%;">Base64<span style="font-family: 宋体;">是<span style="color: red;">用</span></span><span style="color: red;">64</span><span style="font-family: 宋体; color: red;">个可见字符表示任意字节</span><span style="font-family: 宋体;">编码方式。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">Base64<span style="font-family: 宋体;">在</span><a href="http://www.ietf.org/rfc/rfc2045.txt">RFC2045</a><span style="font-family: 宋体;">的</span>section 6.8<span style="font-family: 宋体;">（</span>The Base64 Content-Transfer-Encoding is designed to represent arbitrary sequences of octets in a form that need not be humanly readable<span style="font-family: 宋体;">）定义：</span>Base64<span style="font-family: 宋体;">内容传送编码被设计用来把任意序列的</span>8<span style="font-family: 宋体;">位字节描述为一种不易被人直接识别的形式。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">相对于</span>Base64<span style="font-family: 宋体;">，还有</span>Base16<span style="font-family: 宋体;">、</span>Base32<span style="font-family: 宋体;">编码方式，可以参见</span><a href="http://www.ietf.org/rfc/rfc3548.txt">RFC3548</a><span style="font-family: 宋体;">（</span>The Base16, Base32, and Base64 Data Encodings<span style="font-family: 宋体;">）。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">Base64<span style="font-family: 宋体;">编码应用：电子邮件编码传输、广告点击跳转加密编码串、</span>Cookie<span style="font-family: 宋体;">串二进制内容编码。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span id="more-326"></span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 12pt; line-height: 125%; font-family: 宋体;">编码范围</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">一个字节的编码范围是</span>[0x00, 0xff]<span style="font-family: 宋体;">，共</span>8<span style="font-family: 宋体;">个位，</span>256<span style="font-family: 宋体;">个字符（可称为一个<span style="color: red;">八位组或</span></span><span style="color: red;">Base256</span><span style="font-family: 宋体;">）。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">Base64<span style="font-family: 宋体;">的编码范围是</span>[0x00, 0x3f]<span style="font-family: 宋体;">，共</span>6<span style="font-family: 宋体;">个位，</span>64<span style="font-family: 宋体;">个字符（也为一个<span style="color: red;">六位组</span>）。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">Base64<span style="font-family: 宋体;">的编码过程就是把八位组变成六位组的过程，每三个</span>8bit<span style="font-family: 宋体;">的字节转换为四个</span>6bit<span style="font-family: 宋体;">的字节（</span>3*8 = 4*6 = 24<span style="font-family: 宋体;">），然后把</span>6bit<span style="font-family: 宋体;">再添两位高位</span>0<span style="font-family: 宋体;">，组成四个</span>8bit<span style="font-family: 宋体;">的字节。也就是说，转换后的字符串理论上要比原来的长</span>1/3<span style="font-family: 宋体;">（</span><span style="color: red;">3</span><span style="font-family: 宋体; color: red;">字节编码成</span><span style="color: red;">4</span><span style="font-family: 宋体; color: red;">字节</span><span style="font-family: 宋体;">）。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">Base64<span style="font-family: 宋体;">使用的映射字符：</span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border: medium none;">
<tbody>
<tr>
<td style="width: 33.75pt; border: 1pt solid black; padding: 0cm 5.4pt;" valign="top" width="45">
<div><span style="font-family: 宋体;">编码</span></div>
</td>
<td style="width: 60.95pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div><span style="font-family: 宋体;">字符</span></div>
</td>
<td style="width: 38.3pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div><span style="font-family: 宋体;">编码</span></div>
</td>
<td style="width: 56.4pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div><span style="font-family: 宋体;">字符</span></div>
</td>
<td style="width: 35.75pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div><span style="font-family: 宋体;">编码</span></div>
</td>
<td style="width: 58.95pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div><span style="font-family: 宋体;">字符</span></div>
</td>
<td style="width: 40.25pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div><span style="font-family: 宋体;">编码</span></div>
</td>
<td style="width: 54.45pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div><span style="font-family: 宋体;">字符</span></div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>0</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>A</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>17</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>R</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>34</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>i</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>51</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>z</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>1</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>B</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>18</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>S</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>35</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>j</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>52</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>0</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>2</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>C</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>19</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>T</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>36</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>k</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>53</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>1</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>3</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>D</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>20</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>U</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>37</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>l</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>54</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>2</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>4</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>E</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>21</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>V</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>38</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>m</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>55</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>3</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>5</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>F</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>22</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>W</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>39</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>n</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>56</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>4</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>6</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>G</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>23</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>X</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>40</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>o</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>57</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>5</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>7</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>H</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>24</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>Y</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>41</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>p</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>58</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>6</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>8</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>I</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>25</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>Z</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>42</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>q</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>59</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>7</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>9</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>J</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>26</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>a</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>43</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>r</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>60</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>8</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>10</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>K</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>27</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>b</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>44</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>s</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>61</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>9</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>11</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>L</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>28</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>c</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>45</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>t</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div><span style="color: red;">62</span></div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div><span style="color: red;">+</span></div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>12</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>M</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>29</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>d</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>46</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>u</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div><span style="color: red;">63</span></div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div><span style="color: red;">/</span></div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>13</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>N</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>30</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>e</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>47</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>v</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>&nbsp;</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>&nbsp;</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>14</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>O</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>31</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>f</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>48</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>w</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div><span style="color: red;">pad</span></div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div><span style="color: red;">=</span></div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>15</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>P</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>32</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>g</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>49</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>x</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>&nbsp;</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>&nbsp;</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>16</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>Q</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>33</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>h</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>50</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>y</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>&nbsp;</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>&nbsp;</div>
</td>
</tr>
</tbody>
</table>
</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">pad<span style="font-family: 宋体;">是填充字符，当转换字节不是</span>3<span style="font-family: 宋体;">的倍数时，就用</span>pad<span style="font-family: 宋体;">字符填充补齐。<span style="color: red;">填充字符数</span></span><span style="color: red;">=</span><span style="font-family: 宋体; color: red;">转换字节数</span><span style="color: red;"> MOD 3</span><span style="font-family: 宋体;">。第</span>62<span style="font-family: 宋体;">，</span>63<span style="font-family: 宋体;">，</span>pad<span style="font-family: 宋体;">字符可以根据使用场合来自定义。譬如在</span>URL<span style="font-family: 宋体;">串里，</span>=<span style="font-family: 宋体;">表示特殊意义，就不能使用</span>=<span style="font-family: 宋体;">作为填充字符。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 12pt; line-height: 125%; font-family: 宋体;">编码举例</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">如果字节串是</span>3<span style="font-family: 宋体;">的倍数，刚好对齐。下面是</span>3<span style="font-family: 宋体;">字节编码成</span>4<span style="font-family: 宋体;">字节：</span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border: medium none;">
<tbody>
<tr>
<td style="width: 85.2pt; border: 1pt solid black; padding: 0cm 5.4pt;" valign="top" width="114">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">转换前</span>bit<span style="font-family: 宋体;">内容</span></div>
</td>
<td style="width: 69.05pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="92">
<div style="margin-bottom: 3.9pt; line-height: 125%;">12345678</div>
</td>
<td style="width: 70.9pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;">12345678</div>
</td>
<td style="width: 70.85pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="94">
<div style="margin-bottom: 3.9pt; line-height: 125%;">12345678</div>
</td>
<td style="width: 70.9pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
</td>
</tr>
<tr>
<td style="width: 85.2pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="114">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">转换后</span>bit<span style="font-family: 宋体;">内容</span></div>
</td>
<td style="width: 69.05pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="92">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>123456</div>
</td>
<td style="width: 70.9pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>781234</div>
</td>
<td style="width: 70.85pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="94">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>567812</div>
</td>
<td style="width: 70.9pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>345678</div>
</td>
</tr>
</tbody>
</table>
</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">如果字节串不是</span>3<span style="font-family: 宋体;">的位数，不足的bit用0填充，不足的字节使用填充字符。下面是</span>2<span style="font-family: 宋体;">字节编码成</span>4<span style="font-family: 宋体;">字节：</span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border: medium none;">
<tbody>
<tr>
<td style="width: 85.2pt; border: 1pt solid black; padding: 0cm 5.4pt;" valign="top" width="114">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">转换前</span>bit<span style="font-family: 宋体;">内容</span></div>
</td>
<td style="width: 69.05pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="92">
<div style="margin-bottom: 3.9pt; line-height: 125%;">12345678</div>
</td>
<td style="width: 70.9pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;">12345678</div>
</td>
<td style="width: 70.85pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="94">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">pad</span></div>
</td>
<td style="width: 70.9pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
</td>
</tr>
<tr>
<td style="width: 85.2pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="114">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">转换后</span>bit<span style="font-family: 宋体;">内容</span></div>
</td>
<td style="width: 69.05pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="92">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>123456</div>
</td>
<td style="width: 70.9pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>781234</div>
</td>
<td style="width: 70.85pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="94">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>5678<span style="color: red;">00</span></div>
</td>
<td style="width: 70.9pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">=</span></div>
</td>
</tr>
</tbody>
</table>
</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">如：&ldquo;张&rdquo;占用</span>2<span style="font-family: 宋体;">个字节，字节内容是：</span>11010101 11000101<span style="font-family: 宋体;">，</span>16<span style="font-family: 宋体;">进制（</span>Base16<span style="font-family: 宋体;">）表示就是：</span>D5C5<span style="font-family: 宋体;">。编码成</span>Base64<span style="font-family: 宋体;">，需要使用填充字符补齐成</span>3<span style="font-family: 宋体;">字节再编码，编码结果是</span>1iU=</div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border: medium none;">
<tbody>
<tr>
<td style="width: 85.2pt; border: 1pt solid black; padding: 0cm 5.4pt;" valign="top" width="114">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">转换前</span>bit<span style="font-family: 宋体;">内容</span></div>
</td>
<td style="width: 69.05pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="92">
<div style="margin-bottom: 3.9pt; line-height: 125%;">11010101</div>
</td>
<td style="width: 70.9pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;">11000101</div>
</td>
<td style="width: 70.85pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="94">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">pad</span></div>
</td>
<td style="width: 70.9pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
</td>
</tr>
<tr>
<td style="width: 85.2pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="114">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">转换后</span>bit<span style="font-family: 宋体;">内容</span></div>
</td>
<td style="width: 69.05pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="92">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>110101</div>
</td>
<td style="width: 70.9pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>011100</div>
</td>
<td style="width: 70.85pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="94">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>0101<span style="color: red;">00</span></div>
</td>
<td style="width: 70.9pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">=</span></div>
</td>
</tr>
<tr>
<td style="width: 85.2pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="114">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">转换后字符</span></div>
</td>
<td style="width: 69.05pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="92">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">1</span><span style="font-family: 宋体; color: red;">（</span><span style="color: red;">53</span><span style="font-family: 宋体; color: red;">）</span></div>
</td>
<td style="width: 70.9pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">i</span><span style="font-family: 宋体; color: red;">（</span><span style="color: red;">34</span><span style="font-family: 宋体; color: red;">）</span></div>
</td>
<td style="width: 70.85pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="94">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">U</span><span style="font-family: 宋体; color: red;">（</span><span style="color: red;">20</span><span style="font-family: 宋体; color: red;">）</span></div>
</td>
<td style="width: 70.9pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">=</span></div>
</td>
</tr>
</tbody>
</table>
</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 12pt; line-height: 125%; font-family: 宋体;">编码过程</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">第一个字符通过右移</span>2<span style="font-family: 宋体;">位获得第一个目标字符的</span>Base64<span style="font-family: 宋体;">表位置，根据这个数值取到表上相应的字符，就是第一个目标字符。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">然后将第一个字符左移</span>4 <span style="font-family: 宋体;">位加上第二个字符右移</span>4<span style="font-family: 宋体;">位，即获得第二个目标字符。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">再将第二个字符左移</span>2<span style="font-family: 宋体;">位加上第三个字符右移</span>6<span style="font-family: 宋体;">位，获得第三个目标字符。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">最后取第三个字符的右</span>6<span style="font-family: 宋体;">位即获得第四个目标字符。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">在以上的每一个步骤之后，再把结果与</span> 0x3f <span style="font-family: 宋体;">进行</span> AND <span style="font-family: 宋体;">位操作，就可以得到编码后的字符了。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">如果原文字节数不是</span>3<span style="font-family: 宋体;">的倍数，补齐尾部不足的字节使用填充字符。</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2010/326_base64-encode.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Mysql跨库主从热备失效问题</title>
		<link>http://www.shenmiguo.com/archives/2009/321_mysql-replications.html</link>
		<comments>http://www.shenmiguo.com/archives/2009/321_mysql-replications.html#comments</comments>
		<pubDate>Thu, 29 Oct 2009 06:51:10 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[程序设计]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=321</guid>
		<description><![CDATA[在InnoDB引擎下发现，Mysql的主从热备存在数据不一致的问题，一些数据没有成功同步到备机。在use databases后，更新的表必须是当前选择的database才同步。譬如连上Mysql服务后操作： USE test2; UPDATE client SET name=&#39;test&#39; WHERE uid=1; 数据未能同步到备机，而使用use &#160;test后，才可以成功同步，如下方式： USE test; UPDATE client SET name=&#39;test&#39; WHERE uid=1; &#160; 仔细看Mysql手册，发现同步启动选项中还有玄机，只设置replicate-do-db指定同步数据库还不够。是没有设置replicate-wild-do-table导致的跨库同步问题。Mysql默认是同步指定数据库下的更新操作，若要跨库操作更新同步，就必须指定replicate-wild-do-table参数。下面是Mysql手册中对replicate-do-db和replicate-wild-do-table启动选项的说明： &#160; &#8211;replicate-do-db=db_name 告诉slave只同步那些缺省数据库是 db_name (也就是用 USE 选中的)的语句。想要指定更多的数据库，只需多次使用该选项，每次指定一个数据库。注意，类似 UPDATE some_db.some_table SET foo=&#39;bar&#39; 这样的跨库操作语句以及没有选中数据库的操作都不会被同步。如果必须使用跨库操作，要确保使用MySQL 3.23.28或更高，并且使用 &#8211;replicate-wild-do-table=db_name.% 选项。请仔细阅读最后面的注意事项。 下面是一个不能按照预期工作的例子：如果启动slave时使用 &#8211;replicate-do-db=sales 选项，并且在master上执行下列语句，那么这个 UPDATE 语句不会被同步： USE prices; UPDATE sales.january SET amount=amount+1000; 如果需要同步跨库操作，只需使用 &#8211;replicate-wild-do-table=db_name.% 选项。这个&#34;只检查缺省数据库&#34;特性的主要原因是因为想要单从一个语句中判断是否要被同步比较困难(例如，使用多表 DELETE 或者 UPDATE，这就跨库了)。不过想要检查是否是缺省数据库却很快。 &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>
	<span style="font-family: 宋体;">在</span>InnoDB<span style="font-family: 宋体;">引擎下发现，</span>Mysql<span style="font-family: 宋体;">的主从热备存在数据不一致的问题，一些数据没有成功同步到备机。在</span>use databases<span style="font-family: 宋体;">后，更新的表必须是当前选择的</span>database<span style="font-family: 宋体;">才同步。譬如连上</span>Mysql<span style="font-family: 宋体;">服务后操作：</span></p>
<p>
	<span style="font-family: 宋体;"><span id="more-321"></span></span></p>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<i>USE test2;</i></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<i>UPDATE client SET name=&#39;test&#39; WHERE uid=1;</i></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">数据未能同步到备机，而使用</span>use &nbsp;test<span style="font-family: 宋体;">后，才可以成功同步，如下方式：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<i>USE test; </i></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<i>UPDATE client SET name=&#39;test&#39; WHERE uid=1;</i></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">仔细看</span>Mysql<span style="font-family: 宋体;">手册，发现同步启动选项中还有玄机，只设置</span>replicate-do-db<span style="font-family: 宋体;">指定同步数据库还不够。是没有设置</span>replicate-wild-do-table<span style="font-family: 宋体;">导致的跨库同步问题。</span>Mysql<span style="font-family: 宋体;">默认是同步指定数据库下的更新操作，若要跨库操作更新同步，就必须指定</span>replicate-wild-do-table<span style="font-family: 宋体;">参数。下面是</span>Mysql<span style="font-family: 宋体;">手册中对</span>replicate-do-db<span style="font-family: 宋体;">和</span>replicate-wild-do-table<span style="font-family: 宋体;">启动选项的说明：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="color: red;">&#8211;replicate-do-db=db_name</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">告诉</span>slave<span style="font-family: 宋体;">只同步那些缺省数据库是</span> db_name (<span style="font-family: 宋体;">也就是用</span> USE <span style="font-family: 宋体;">选中的</span>)<span style="font-family: 宋体;">的语句。想要指定更多的数据库，只需多次使用该选项，每次指定一个数据库。注意，类似</span> UPDATE some_db.some_table SET foo=&#39;bar&#39; <span style="font-family: 宋体;">这样的<span style="color: red;">跨库操作语句以及没有选中数据库的操作都不会被同步</span>。如果必须使用跨库操作，要确保使用</span>MySQL 3.23.28<span style="font-family: 宋体;">或更高，并且使用</span> &#8211;replicate-wild-do-table=db_name.% <span style="font-family: 宋体;">选项。请仔细阅读最后面的注意事项。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">下面是一个不能按照预期工作的例子：如果启动</span>slave<span style="font-family: 宋体;">时使用</span> &#8211;replicate-do-db=sales <span style="font-family: 宋体;">选项，并且在</span>master<span style="font-family: 宋体;">上执行下列语句，那么这个</span> UPDATE <span style="font-family: 宋体;">语句不会被同步：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<i>USE prices;</i></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<i>UPDATE sales.january SET amount=amount+1000;</i></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体; color: red;">如果需要同步跨库操作，只需使用</span><span style="color: red;"> &#8211;replicate-wild-do-table=db_name.% </span><span style="font-family: 宋体; color: red;">选项</span><span style="font-family: 宋体;">。这个</span>&quot;<span style="font-family: 宋体;">只检查缺省数据库</span>&quot;<span style="font-family: 宋体;">特性的主要原因是因为想要单从一个语句中判断是否要被同步比较困难</span>(<span style="font-family: 宋体;">例如，使用多表</span> DELETE <span style="font-family: 宋体;">或者</span> UPDATE<span style="font-family: 宋体;">，这就跨库了</span>)<span style="font-family: 宋体;">。不过想要检查是否是缺省数据库却很快。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="color: red;">&#8211;replicate-wild-do-table=db_name.tbl_name</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">限制</span>slave<span style="font-family: 宋体;">只同步那些匹配指定模式的数据表。模式中可以包含通配符</span> `%` <span style="font-family: 宋体;">和</span> `_`<span style="font-family: 宋体;">，它们的含义和</span> LIKE <span style="font-family: 宋体;">模式一样。想要指定更多的数据表，只需多次使用该选项，每次指定一个数据表。请仔细阅读最后面的注意事项。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">例如：</span> &#8211;replicate-wild-do-table=foo%.bar% <span style="font-family: 宋体;">会同步所有以</span> foo <span style="font-family: 宋体;">开头的数据库下的以</span> bar <span style="font-family: 宋体;">开头的数据表上的更新操作。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">如果匹配模式是</span> %<span style="font-family: 宋体;">，则匹配所有的表名，且应用到数据库级语句</span>(CREATE DATABASE, DROP DATABASE,<span style="font-family: 宋体;">和</span> ALTER DATABASE)<span style="font-family: 宋体;">。例如，使用</span> &#8211;replicate-wild-do-table=foo%.% <span style="font-family: 宋体;">选项的话，所有匹配</span> foo% <span style="font-family: 宋体;">模式的数据库级操作都会被同步。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">如果想要在数据库</span>/<span style="font-family: 宋体;">表模式中包含原义通配符，需要用反斜杠来转义它们。例如，想要同步</span> my_own%db <span style="font-family: 宋体;">数据库下的所有表，但是不想同步</span> my1ownAABCdb <span style="font-family: 宋体;">数据库下的表，就需要转义字符</span> `_`<span style="font-family: 宋体;">：</span> &#8211;replicate-wild-do-table=my\_own\%db<span style="font-family: 宋体;">。如果是在命令行中使用这个选项，就可能需要两个反斜杠来转义，这依赖于命令行解释器。例如，在</span> bash shell<span style="font-family: 宋体;">下，就需要输入：</span> &#8211;replicate-wild-do-table=my\\_own\\%db<span style="font-family: 宋体;">。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体; color: red;">还存在一些问题</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">不管有没有</span>replicate-wild-do-table<span style="font-family: 宋体;">选项，更新操作必须是</span>mysql<span style="font-family: 宋体;">连接已经有选择的数据库了才进行，譬如新建的</span>mysql<span style="font-family: 宋体;">（新连接是没有默认选择的</span>database<span style="font-family: 宋体;">的）连接中执行：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<i>UPDATE test.client SET name=&#39;test&#39; WHERE uid=1;</i></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">这条更新无法同步到备机，必须在</span>update<span style="font-family: 宋体;">前</span>use database<span style="font-family: 宋体;">操作，该</span>database<span style="font-family: 宋体;">必须是</span>replicate-wild-do-table<span style="font-family: 宋体;">中指定的</span>database<span style="font-family: 宋体;">。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体; color: red;">保险的解决方式</span><span style="font-family: 宋体;">：连接上</span>mysql<span style="font-family: 宋体;">后，调用</span>mysql_select_db()<span style="font-family: 宋体;">选择数据库，之后进行的更新操作就可以自动同步了。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="color: red;">SQL</span><span style="font-family: 宋体; color: red;">模式匹配</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	SQL<span style="font-family: 宋体;">的模式匹配允许你使用&ldquo;</span>_<span style="font-family: 宋体;">&rdquo;匹配任何单个字符，而&ldquo;</span>%<span style="font-family: 宋体;">&rdquo;匹配任意数目字符</span>(<span style="font-family: 宋体;">包括零个字符</span>)<span style="font-family: 宋体;">。在</span> MySQL<span style="font-family: 宋体;">中，</span>SQL<span style="font-family: 宋体;">的模式缺省是忽略大小写的。下面显示一些例子。注意在你使用</span>SQL<span style="font-family: 宋体;">模式时，你不能使用</span>=<span style="font-family: 宋体;">或</span>!=<span style="font-family: 宋体;">；而使用</span>LIKE<span style="font-family: 宋体;">或</span>NOT LIKE<span style="font-family: 宋体;">比较操作符。</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2009/321_mysql-replications.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Apache和Mysql的并发配置</title>
		<link>http://www.shenmiguo.com/archives/2009/320_apache-mysql-perf.html</link>
		<comments>http://www.shenmiguo.com/archives/2009/320_apache-mysql-perf.html#comments</comments>
		<pubDate>Tue, 27 Oct 2009 10:24:05 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=320</guid>
		<description><![CDATA[在测试页面并发压力的时候，并发到80以后，响应速度急剧下降，CPU占用率急剧上升。经分析，是Apache并发数和Mysql并发数匹配问题。 Mysql并发瓶颈 Mysql的连接数到达150以上的时候，服务器4核cpu占有率会急增，性能会急剧下降。Apache并发80的情况下，mysql连接数基本上到了配置的满额200（max-connections=200）。 &#160; Apache与mysql的并发关系 Apache最大并发数配置是600，大于mysql最大并发数200，每个apache请求要对应一个mysql连接，而Apache的并发能力要远大于mysql服务器的并发能力。高并发情况下，mysql的查询还没有返回结果，但下一次的apache请求已经到了，堆积效果就是mysql都是满额并发运行，可能导致连接mysql错误：&#8220;too many connections&#8230;&#8221;。 &#160; Apache做Mysql的连接池 从上面分析可以看出， mysql_pconnect连接Mysql，但没有控制和管理mysql连接数，可能导致Mysql服务器忙死。只要有连接池，就可以解决问题。 利用apache做mysql的连接池，即控制apache的并发数。apache配置最大并发数（如20）小于mysql最大连接数。当并发过大的时候，就自动利用apache的队列来达到连接池的目的。虽然牺牲了apache性能，但保证了业务的稳定性和安全性，也不会导致Mysql服务器忙死。 apache最大并发数配置的一个缺陷是：无法配置虚拟主机的并发数，只能配置全局并发数。 使用Apache的prefork模式配置并发数： http://www.shenmiguo.com/archives/2009/318_apache-mpm.html Mysql持久连接介绍： http://www.shenmiguo.com/archives/2009/319_mysql-pconnect.html]]></description>
			<content:encoded><![CDATA[<p>
	<span class="Apple-style-span" style="line-height: 18px; "><span style="font-family:宋体;">在测试页面并发压力的时候，并发到</span>80<span style="font-family:宋体;">以后，响应速度急剧下降，</span>CPU<span style="font-family:宋体;">占用率急剧上升。经分析，是</span>Apache<span style="font-family:宋体;">并发数和</span>Mysql<span style="font-family:宋体;">并发数匹配问题。</span></span></p>
<div style="line-height:150%">
	<span id="more-320"></span></div>
<div style="line-height:150%">
	<b>Mysql</b><b><span style="font-family:宋体;">并发瓶颈</span></b></div>
<div style="line-height:150%">
	Mysql<span style="font-family:宋体;">的连接数到达</span>150<span style="font-family:宋体;">以上的时候，服务器</span>4<span style="font-family:宋体;">核</span>cpu<span style="font-family:宋体;">占有率会急增，性能会急剧下降。</span>Apache<span style="font-family:宋体;">并发</span>80<span style="font-family:宋体;">的情况下，</span>mysql<span style="font-family:宋体;">连接数基本上到了配置的满额</span>200<span style="font-family:宋体;">（</span>max-connections=200<span style="font-family:宋体;">）。</span></div>
<div style="line-height:150%">
	&nbsp;</div>
<div style="line-height:150%">
	<b>Apache</b><b><span style="font-family:宋体;">与</span>mysql</b><b><span style="font-family:宋体;">的并发关系</span></b></div>
<div style="line-height:150%">
	Apache<span style="font-family:宋体;">最大并发数配置是</span>600<span style="font-family:宋体;">，大于</span>mysql<span style="font-family:宋体;">最大并发数</span>200<span style="font-family:宋体;">，每个</span>apache<span style="font-family:宋体;">请求要对应一个</span>mysql<span style="font-family:宋体;">连接，而</span>Apache<span style="font-family:宋体;">的并发能力要远大于</span>mysql<span style="font-family:宋体;">服务器的并发能力。高并发情况下，</span>mysql<span style="font-family:宋体;">的查询还没有返回结果，但下一次的</span>apache<span style="font-family:宋体;">请求已经到了，堆积效果就是</span>mysql<span style="font-family:宋体;">都是满额并发运行，可能导致连接</span>mysql<span style="font-family:宋体;">错误：&ldquo;</span>too many connections<span style="font-family:宋体;">&hellip;&rdquo;。</span></div>
<div style="line-height:150%">
	&nbsp;</div>
<div style="line-height:150%">
	<b>Apache</b><b><span style="font-family:宋体;">做</span>Mysql</b><b><span style="font-family:宋体;">的连接池</span></b></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">从上面分析可以看出，</span> mysql_pconnect<span style="font-family:宋体;">连接</span>Mysql<span style="font-family:宋体;">，但没有控制和管理</span>mysql<span style="font-family:宋体;">连接数，可能导致</span>Mysql<span style="font-family:宋体;">服务器忙死。只要有连接池，就可以解决问题。</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">利用</span>apache<span style="font-family:宋体;">做</span>mysql<span style="font-family:宋体;">的连接池，即控制</span>apache<span style="font-family:宋体;">的并发数。</span>apache<span style="font-family:宋体;">配置最大并发数（如</span>20<span style="font-family:宋体;">）小于</span>mysql<span style="font-family:宋体;">最大连接数。当并发过大的时候，就自动利用</span>apache<span style="font-family:宋体;">的队列来达到连接池的目的。虽然牺牲了</span>apache<span style="font-family:宋体;">性能，但保证了业务的稳定性和安全性，也不会导致</span>Mysql<span style="font-family:宋体;">服务器忙死。</span></div>
<div style="line-height:150%">
	apache<span style="font-family:宋体;">最大并发数配置的一个缺陷是：无法配置虚拟主机的并发数，只能配置全局并发数。</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">使用</span>Apache<span style="font-family:宋体;">的</span>prefork<span style="font-family:宋体;">模式配置并发数：</span></div>
<div style="line-height:150%">
	<a href="http://www.shenmiguo.com/archives/2009/318_apache-mpm.html">http://www.shenmiguo.com/archives/2009/318_apache-mpm.html</a></div>
<div style="line-height:150%">
	Mysql<span style="font-family:宋体;">持久连接介绍：</span></div>
<div style="line-height:150%">
	<a href="http://www.shenmiguo.com/archives/2009/319_mysql-pconnect.html">http://www.shenmiguo.com/archives/2009/319_mysql-pconnect.html</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2009/320_apache-mysql-perf.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Mysql持久连接</title>
		<link>http://www.shenmiguo.com/archives/2009/319_mysql-pconnect.html</link>
		<comments>http://www.shenmiguo.com/archives/2009/319_mysql-pconnect.html#comments</comments>
		<pubDate>Tue, 27 Oct 2009 09:16:12 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[程序设计]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=319</guid>
		<description><![CDATA[长短连接区别 不同于mysql_connect的短连接，mysql_pconnect持久连接的时候，将先尝试寻找一个在同一个主机上用同样的用户名和密码已经打开的（持久）连接，如果找到，则返回此连接标识而不打开新连接。 当执行完毕后，到 mysql 服务器的持久连接不会被关闭，此连接将保持打开以备以后使用，即mysql_close() 不会关闭由 mysql_pconnect() 建立的连接。 &#160; Apache与长连接管理 PHP本身并没有数据库连接池的概念，但是Apache有进程池的概念, 一个Apache子进程结束后会被放回进程池, 这也就使得用mysql_pconnect打开的的那个mysql连接资源可以不被释放，而是依附在相应的Apache子进程上保存到了进程池中。于是在下一个连接请求时它就可以被复用。但是在Apache并发访问量大的时候，如果使用mysql_pconnect，会由于之前的Apache子进程占用的MySQL连接没有close, 很快使MySQL达到最大连接数，使得之后的请求可能得不到响应。 当然，高并发情况下也不能怪罪pconnect，用短连接频繁连接mysql，也一样有问题。在没有连接池的情况下，用apache做连接池管理是比较好的选择。]]></description>
			<content:encoded><![CDATA[<p>
	<span class="Apple-style-span" style="line-height: 18px; "><b><span style="font-size:12.0pt;line-height:150%;font-family:宋体;">长短连接区别</span></b></span></p>
<div style="line-height:150%">
	<span style="font-family:宋体;">不同于</span>mysql_connect<span style="font-family:宋体;">的短连接，</span>mysql_pconnect<span style="font-family:宋体;">持久连接的时候，将先尝试寻找一个在同一个主机上用同样的用户名和密码已经打开的（持久）连接，如果找到，则返回此连接标识而不打开新连接。</span></div>
<div style="line-height:150%">
	<span id="more-319"></span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">当执行完毕后，到</span> mysql <span style="font-family:宋体;">服务器的持久连接不会被关闭，此连接将保持打开以备以后使用，即</span>mysql_close() <span style="font-family:宋体;">不会关闭由</span> mysql_pconnect() <span style="font-family:宋体;">建立的连接。</span></div>
<div style="line-height:150%">
	&nbsp;</div>
<div style="line-height:150%">
	<b><span style="font-size:12.0pt;line-height:150%">Apache</span></b><b><span style="font-size:12.0pt;line-height:<br />
150%;font-family:宋体;">与长连接管理</span></b></div>
<div style="line-height:150%">
	PHP<span style="font-family:宋体;">本身并没有数据库连接池的概念，但是</span>Apache<span style="font-family:宋体;">有进程池的概念</span>, <span style="font-family:宋体;">一个</span>Apache<span style="font-family:宋体;">子进程结束后会被放回进程池</span>, <span style="font-family:宋体;">这也就使得用</span>mysql_pconnect<span style="font-family:宋体;">打开的的那个</span>mysql<span style="font-family:宋体;">连接资源可以不被释放，而是依附在相应的</span>Apache<span style="font-family:宋体;">子进程上保存到了进程池中。于是在下一个连接请求时它就可以被复用。但是在</span>Apache<span style="font-family:宋体;">并发访问量大的时候，如果使用</span>mysql_pconnect<span style="font-family:宋体;">，会由于之前的</span>Apache<span style="font-family:宋体;">子进程占用的</span>MySQL<span style="font-family:宋体;">连接没有</span>close, <span style="font-family:宋体;">很快使</span>MySQL<span style="font-family:宋体;">达到最大连接数，使得之后的请求可能得不到响应。</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">当然，高并发情况下也不能怪罪</span>pconnect<span style="font-family:宋体;">，用短连接频繁连接</span>mysql<span style="font-family:宋体;">，也一样有问题。在没有连接池的情况下，用</span>apache<span style="font-family:宋体;">做连接池管理是比较好的选择。</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2009/319_mysql-pconnect.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Apache多路处理与并发配置</title>
		<link>http://www.shenmiguo.com/archives/2009/318_apache-mpm.html</link>
		<comments>http://www.shenmiguo.com/archives/2009/318_apache-mpm.html#comments</comments>
		<pubDate>Tue, 27 Oct 2009 07:55:15 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[程序设计]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mpm]]></category>
		<category><![CDATA[并发]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=318</guid>
		<description><![CDATA[Apache通过多路处理模块（Multi-Processing Module）MPM控制并发，常用的有两种模式：prefork（默认）和worker，通过apachectrl &#160;-l可看到当前加载MPM模块（prefork.c或者worker.c）。 prefork模式是预派生子进程方式，使用多个子进程，每个子进程只有一个线程。每个进程在某个确定的时间只能维持一个连接。 worker模式是多线程与多进程混合方式，使用多个子进程，每个子进程有多个线程。每个线程在某个确定的时间只能维持一个连接。 总的来说，prefork方式速度要稍高于worker，然而它需要的cpu和memory资源也稍多于woker。 &#160; prefork模式 httpd.conf中，prefork的配置如下： &#60;IfModule prefork.c&#62; ServerLimit &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;2000 StartServers&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 300 MinSpareServers&#160;&#160;&#160;&#160;&#160; 5 MaxSpareServers&#160;&#160;&#160;&#160; 10 MaxClients&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;600 MaxRequestsPerChild&#160;10000 &#60;/IfModule&#62; prefork的工作原理是，控制进程在最初建立&#34;StartServers&#34;个子进程后，为了满足&#34;MinSpareServers&#34;设置的需要创建一个进程，等待一秒钟，继续创建两个，再等待一秒钟，继续创建四个&#8230;&#8230;如此按指数级增加创建的进程数，最多达到每秒32个，直到满足 MinSpareServers设置的值为止。这就是预派生（prefork）的由来。这种模式可以不必在请求到来时再产生新的进程，从而减小了系统开销以增加性能。 MaxClients是最重要的一个参数。可通过MaxClients来控制Apache并发数。 &#160; prefork指令 ServerLimit 默认的MaxClient最大是600个线程,如果想设置更大的值，就的加上ServerLimit这个参数。20000是ServerLimit这个参数的最大值。如果需要更大，则必须编译apache，此前都是不需要重新编译Apache。 生效前提：必须放在其他指令的前面。 StartServers 指定服务器启动时建立的子进程数量。应该要小于等于MaxClients。 MinSpareServers 指定空闲子进程的最小数量，默认为5。如果当前空闲子进程数少于MinSpareServers ，那么Apache将以最大每秒一个的速度产生新的子进程。此参数不要设的太大。 MaxSpareServers 设置空闲子进程的最大数量，默认为10。如果当前有超过MaxSpareServers数量的空闲子进程，那么父进程将杀死多余的子进程。此参数不要设的太大。如果你将该指令的值设置为比MinSpareServers小，Apache将会自动将其修改成MinSpareServers+1。 MaxClients 限定同一时间客户端最大接入请求的数量(单个进程并发线程数)，默认为600。任何超过MaxClients限制的请求都将进入等候队列,一旦一个链接被释放，队列中的请求将得到服务。要增大这个值，你必须同时增大ServerLimit。 MaxRequestsPerChild MaxRequestsPerChild指令控制服务器杀死旧进程产生新进程的频率。每个子进程在其生存期内允许伺服的最大请求数量，默认为10000。到达MaxRequestsPerChild的限制后，子进程将会结束。如果MaxRequestsPerChild为&#8221;0&#8243;，子进程将永远不会结束。将MaxRequestsPerChild设置成非零值有两个好处： 1. 可以防止(偶然的)内存泄漏无限进行，从而耗尽内存。 2. 给进程一个有限寿命，从而有助于当服务器负载减轻的时候减少活动进程的数量。 &#160; worker模式 httpd.conf中，prefork的配置如下： &#60;IfModule worker.c&#62; ServerLimit 25 ThreadLimit &#160;&#160;&#160;&#160;&#160;&#160;&#160;200 [...]]]></description>
			<content:encoded><![CDATA[<p>
	<span class="Apple-style-span" style="line-height: 18px; ">Apache<span style="font-family:宋体;">通过<b>多路处理模块</b>（</span>Multi-Processing Module<span style="font-family:宋体;">）</span>MPM<span style="font-family:宋体;">控制并发，常用的有两种模式：</span>prefork<span style="font-family:宋体;">（默认）和</span>worker<span style="font-family:宋体;">，通过</span><span style="color:red">apachectrl &nbsp;-l</span><span style="font-family:宋体;">可看到当前加载</span>MPM<span style="font-family:宋体;">模块（</span>prefork.c<span style="font-family:宋体;">或者</span>worker.c<span style="font-family:宋体;">）。</span></span></p>
<div style="line-height:150%;">
	<span id="more-318"></span></div>
<div style="line-height:150%">
	<span style="color:red">prefork</span><span style="font-family:宋体;">模式是预派生子进程方式，使用多个子进程，每个子进程只有一个线程。每个进程在某个确定的时间只能维持一个连接。</span></div>
<div style="line-height:150%">
	<span style="color:red">worker</span><span style="font-family:宋体;">模式是多线程与多进程混合方式，使用多个子进程，每个子进程有多个线程。每个线程在某个确定的时间只能维持一个连接。</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">总的来说，</span>prefork<span style="font-family:宋体;">方式速度要稍高于</span>worker<span style="font-family:宋体;">，然而它需要的</span>cpu<span style="font-family:宋体;">和</span>memory<span style="font-family:宋体;">资源也稍多于</span>woker<span style="font-family:宋体;">。</span></div>
<div style="line-height:150%">
	&nbsp;</div>
<div style="line-height:150%;">
	<b><span style="font-size:12.0pt;<br />
line-height:150%">prefork</span></b><b><span style="font-size:12.0pt;line-height:150%;font-family:宋体;">模式</span></b></div>
<div style="line-height:150%">
	httpd.conf<span style="font-family:宋体;">中，</span>prefork<span style="font-family:宋体;">的配置如下：</span></div>
<div style="line-height:150%">
	&lt;IfModule prefork.c&gt;</div>
<div style="line-height:150%">
	ServerLimit <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2000</span></div>
<div style="line-height:150%">
	StartServers<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 300</span></div>
<div style="line-height:150%">
	MinSpareServers<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5</span></div>
<div style="line-height:150%">
	MaxSpareServers<span>&nbsp;&nbsp;&nbsp;&nbsp; 10</span></div>
<div style="line-height:150%">
	MaxClients<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;600</span></div>
<div style="line-height:150%">
	MaxRequestsPerChild&nbsp;10000</div>
<div style="line-height:150%">
	&lt;/IfModule&gt;</div>
<div style="line-height:150%">
	prefork<span style="font-family:宋体;">的工作原理是，控制进程在最初建立</span>&quot;StartServers&quot;<span style="font-family:宋体;">个子进程后，为了满足</span>&quot;MinSpareServers&quot;<span style="font-family:宋体;">设置的需要创建一个进程，等待一秒钟，继续创建两个，再等待一秒钟，继续创建四个&hellip;&hellip;如此按指数级增加创建的进程数，最多达到每秒</span>32<span style="font-family:宋体;">个，直到满足</span> MinSpareServers<span style="font-family:宋体;">设置的值为止。这就是预派生（</span>prefork<span style="font-family:宋体;">）的由来。这种模式可以不必在请求到来时再产生新的进程，从而减小了系统开销以增加性能。</span></div>
<div style="line-height:150%">
	<span style="color:red">MaxClients</span><span style="font-family:宋体;">是最重要的一个参数。可通过</span>MaxClients<span style="font-family:宋体;">来控制</span>Apache<span style="font-family:宋体;">并发数。</span></div>
<div style="line-height:150%">
	&nbsp;</div>
<div style="line-height:150%;">
	<b><span style="font-size:12.0pt;<br />
line-height:150%">prefork</span></b><b><span style="font-size:12.0pt;line-height:150%;font-family:宋体;">指令</span></b></div>
<div style="line-height:150%">
	<span style="color:red">ServerLimit</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">默认的</span>MaxClient<span style="font-family:宋体;">最大是</span>600<span style="font-family:宋体;">个线程</span>,<span style="font-family:宋体;">如果想设置更大的值，就的加上</span>ServerLimit<span style="font-family:宋体;">这个参数。</span>20000<span style="font-family:宋体;">是</span>ServerLimit<span style="font-family:宋体;">这个参数的最大值。如果需要更大，则必须编译</span>apache<span style="font-family:宋体;">，此前都是不需要重新编译</span>Apache<span style="font-family:宋体;">。</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">生效前提：必须放在其他指令的前面。</span></div>
<div style="line-height:150%">
	<span style="color:red">StartServers</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">指定服务器启动时建立的子进程数量。应该要小于等于</span>MaxClients<span style="font-family:宋体;">。</span></div>
<div style="line-height:150%">
	<span style="color:red">MinSpareServers</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">指定空闲子进程的最小数量，默认为</span>5<span style="font-family:宋体;">。如果当前空闲子进程数少于</span>MinSpareServers <span style="font-family:宋体;">，那么</span>Apache<span style="font-family:宋体;">将以最大每秒一个的速度产生新的子进程。此参数不要设的太大。</span></div>
<div style="line-height:150%">
	<span style="color:red">MaxSpareServers</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">设置空闲子进程的最大数量，默认为</span>10<span style="font-family:宋体;">。如果当前有超过</span>MaxSpareServers<span style="font-family:宋体;">数量的空闲子进程，那么父进程将杀死多余的子进程。此参数不要设的太大。如果你将该指令的值设置为比</span>MinSpareServers<span style="font-family:宋体;">小，</span>Apache<span style="font-family:宋体;">将会自动将其修改成</span>MinSpareServers+1<span style="font-family:宋体;">。</span></div>
<div style="line-height:150%">
	<b><span style="color:red">MaxClients</span></b></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">限定同一时间客户端最大接入请求的数量</span>(<span style="font-family:宋体;">单个进程并发线程数</span>)<span style="font-family:宋体;">，默认为</span>600<span style="font-family:宋体;">。任何超过</span>MaxClients<span style="font-family:宋体;">限制的请求都将进入等候队列</span>,<span style="font-family:宋体;">一旦一个链接被释放，队列中的请求将得到服务。要增大这个值，你必须同时增大</span>ServerLimit<span style="font-family:宋体;">。</span></div>
<div style="line-height:150%">
	<span style="color:red">MaxRequestsPerChild</span></div>
<div style="line-height:150%">
	MaxRequestsPerChild<span style="font-family:宋体;">指令控制服务器杀死旧进程产生新进程的频率。每个子进程在其生存期内允许伺服的最大请求数量，默认为</span>10000<span style="font-family:宋体;">。到达</span>MaxRequestsPerChild<span style="font-family:宋体;">的限制后，子进程将会结束。如果</span>MaxRequestsPerChild<span style="font-family:宋体;">为&rdquo;</span>0<span style="font-family:宋体;">&Prime;，子进程将永远不会结束。将</span><span style="color:red">MaxRequestsPerChild</span><span style="font-family:<br />
宋体;color:red">设置成非零值</span><span style="font-family:宋体;">有两个好处：</span></div>
<div style="line-height:150%">
	1. <span style="font-family:宋体;">可以防止</span>(<span style="font-family:宋体;">偶然的</span>)<span style="font-family:宋体;">内存泄漏无限进行，从而耗尽内存。</span></div>
<div style="line-height:150%">
	2. <span style="font-family:宋体;">给进程一个有限寿命，从而有助于当服务器负载减轻的时候减少活动进程的数量。</span></div>
<div style="line-height:150%">
	&nbsp;</div>
<div style="line-height:150%;">
	<b><span style="font-size:12.0pt;<br />
line-height:150%">worker</span></b><b><span style="font-size:12.0pt;line-height:150%;font-family:宋体;">模式</span></b></div>
<div style="line-height:150%">
	httpd.conf<span style="font-family:宋体;">中，</span>prefork<span style="font-family:宋体;">的配置如下：</span></div>
<div style="line-height:150%">
	&lt;IfModule worker.c&gt;</div>
<div style="line-height:150%">
	ServerLimit 25</div>
<div style="line-height:150%">
	ThreadLimit <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;200</span></div>
<div style="line-height:150%">
	StartServers<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 </span></div>
<div style="line-height:150%">
	MaxClients<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 600</span></div>
<div style="line-height:150%">
	MinSpareThreads<span>&nbsp;&nbsp;&nbsp;&nbsp; 50</span></div>
<div style="line-height:150%">
	MaxSpareThreads<span>&nbsp;&nbsp;&nbsp;&nbsp; 100</span></div>
<div style="line-height:150%">
	<span style="color:red">ThreadsPerChild</span><span>&nbsp;&nbsp;&nbsp;&nbsp; 100</span></div>
<div style="line-height:150%">
	MaxRequestsPerChild&nbsp;10000</div>
<div style="line-height:150%">
	&lt;/IfModule&gt;</div>
<div style="line-height:150%">
	worker<span style="font-family:宋体;">的工作原理是，由主控制进程生成</span>&quot;StartServers&quot;<span style="font-family:宋体;">个子进程，每个子进程中包含固定的</span>ThreadsPerChild<span style="font-family:宋体;">线程数，各个线程独立地处理请求。同样，为了不在请求到来时再生成线程，</span>MinSpareThreads<span style="font-family:宋体;">和</span>MaxSpareThreads<span style="font-family:宋体;">设置了最少和最多的空闲线程数；而</span>MaxClients<span style="font-family:宋体;">设置了所有子进程中的线程总数。如果现有子进程中的线程总数不能满足负载，控制进程将派生新的子进程。</span></div>
<div style="line-height:150%">
	<span style="color:red">ThreadsPerChild</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">是</span>worker<span style="font-family:宋体;">模式中与性能相关最密切的指令。这个指令设置了每个子进程建立的线程数。子进程在启动时建立这些线程后就不再建立新的线程了。</span></div>
<div style="line-height:150%">
	&nbsp;</div>
<div style="line-height:150%;">
	<b><span style="font-size:12.0pt;line-height:<br />
150%;font-family:宋体;">资源</span></b></div>
<div style="line-height:150%">
	prefork<span style="font-family:宋体;">文档：</span><a href="http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/prefork.html">http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/prefork.html</a></div>
<div style="line-height:150%">
	workder<span style="font-family:宋体;">文档：</span><a href="http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/worker.html">http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/worker.html</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2009/318_apache-mpm.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Linux建立SSH免密码互信方法</title>
		<link>http://www.shenmiguo.com/archives/2009/316_linux-ssh-trust.html</link>
		<comments>http://www.shenmiguo.com/archives/2009/316_linux-ssh-trust.html#comments</comments>
		<pubDate>Wed, 30 Sep 2009 05:22:14 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[互信]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=316</guid>
		<description><![CDATA[&#160;Linux下，要想scp自动输入远端服务器的密码来拷贝文件，一般借助expect脚本来达到目的。两台服务器之间互信是指，用scp拷贝文件、ssh登陆、rsync同步文件等操作的时候，不需要输入远端服务器的用户密码就可以完成操作。 以下在SUSE 10.1上，来说明如何建立两台服务器的通信互信机制。使用root用户，192.168.0.170若要无密码ssh登陆192.168.0.147机器： 1.&#160;&#160;&#160;&#160;&#160;&#160; 在170上生成认证RSA密钥： ssh-keygen -b 1024 -t rsa 中间过程直接回车。在/root/.ssh2/目录下，生成了两个文件： id_rsa_1024_a（私钥文件放在本地） 和 id_rsa_1024_a.pub（公钥文件放在信任服务器） 为了方便管理，将它们重命名： mv id_rsa_1024_a&#160;&#160;&#160; root_192.168.0.170 mv id_rsa_1024_a.pub&#160;&#160;&#160; root_192.168.0.170.pub 2.&#160;&#160;&#160;&#160;&#160;&#160; 170上，在/root/.ssh2/下，私钥验证文件identification中追加（cat &#62;&#62; identification）： IdKey root_192.168.0.170 3.&#160;&#160;&#160;&#160;&#160;&#160; 将公钥文件拷贝到147上： scp root_192.168.0.170.pub root@192.168.0.147:/root/.ssh2 4.&#160;&#160;&#160;&#160;&#160;&#160; Root用户登陆147，在/root/.ssh2/下，公钥验证文件authorization中追加（cat &#62;&#62; authorization）： Key root_192.168.0.170.pub 这样147上root用户就信任了来自170的root用户通信。在170，往147上scp、ssh、rsync都是免密码了。 &#160; &#160; &#160;]]></description>
			<content:encoded><![CDATA[<p>&nbsp;Linux<span style="font-family: 宋体;">下，要想</span>scp<span style="font-family: 宋体;">自动输入远端服务器的密码来拷贝文件，一般借助</span>expect<span style="font-family: 宋体;">脚本来达到目的。两台服务器之间互信是指，用</span>scp<span style="font-family: 宋体;">拷贝文件、</span>ssh<span style="font-family: 宋体;">登陆、</span>rsync<span style="font-family: 宋体;">同步文件等操作的时候，不需要输入远端服务器的用户密码就可以完成操作。</span></p>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;"><span id="more-316"></span></span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">以下在</span>SUSE 10.1<span style="font-family: 宋体;">上，来说明如何建立两台服务器的通信互信机制。使用</span>root<span style="font-family: 宋体;">用户，</span>192.168.0.170<span style="font-family: 宋体;">若要无密码</span>ssh<span style="font-family: 宋体;">登陆</span>192.168.0.147<span style="font-family: 宋体;">机器：</span></div>
<div style="margin: 0cm 0cm 3.9pt 18pt; text-indent: -18pt; line-height: 125%;"><span>1.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family: 宋体;">在</span>170<span style="font-family: 宋体;">上生成认证</span>RSA<span style="font-family: 宋体;">密钥：</span></div>
<div style="margin: 0cm 0cm 3.9pt 18pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">ssh-keygen -b 1024 -t rsa</span></div>
<div style="margin: 0cm 0cm 3.9pt 18pt; line-height: 125%;"><span style="font-family: 宋体;">中间过程直接回车。在</span>/root/.ssh2/<span style="font-family: 宋体;">目录下，生成了两个文件：</span></div>
<div style="margin-bottom: 3.9pt; text-indent: 18pt; line-height: 125%;">id_rsa_1024_a<span style="font-family: 宋体;">（私钥文件放在本地）</span> <span style="font-family: 宋体;">和</span> id_rsa_1024_a.pub<span style="font-family: 宋体;">（公钥文件放在信任服务器）</span></div>
<div style="margin: 0cm 0cm 3.9pt 18pt; line-height: 125%;"><span style="font-family: 宋体;">为了方便管理，将它们重命名：</span></div>
<div style="margin: 0cm 0cm 3.9pt 18pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">mv id_rsa_1024_a&nbsp;&nbsp;&nbsp; root_192.168.0.170</span></div>
<div style="margin: 0cm 0cm 3.9pt 18pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">mv id_rsa_1024_a.pub&nbsp;&nbsp;&nbsp; root_192.168.0.170.pub</span></div>
<div style="margin: 0cm 0cm 3.9pt 18pt; text-indent: -18pt; line-height: 125%;"><span>2.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>170<span style="font-family: 宋体;">上，在</span>/root/.ssh2/<span style="font-family: 宋体;">下，私钥验证文件</span>identification<span style="font-family: 宋体;">中追加（</span>cat &gt;&gt; identification<span style="font-family: 宋体;">）：</span></div>
<div style="margin: 0cm 0cm 3.9pt 18pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">IdKey root_192.168.0.170</span></div>
<div style="margin: 0cm 0cm 3.9pt 18pt; text-indent: -18pt; line-height: 125%;"><span>3.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family: 宋体;">将公钥文件拷贝到</span>147<span style="font-family: 宋体;">上：</span></div>
<div style="margin: 0cm 0cm 3.9pt 18pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">scp root_192.168.0.170.pub root@192.168.0.147:/root/.ssh2</span></div>
<div style="margin: 0cm 0cm 3.9pt 18pt; text-indent: -18pt; line-height: 125%;"><span>4.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Root<span style="font-family: 宋体;">用户登陆</span>147<span style="font-family: 宋体;">，在</span>/root/.ssh2/<span style="font-family: 宋体;">下，公钥验证文件</span>authorization<span style="font-family: 宋体;">中追加（</span>cat &gt;&gt; authorization<span style="font-family: 宋体;">）：</span></div>
<div style="margin: 0cm 0cm 3.9pt 18pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">Key root_192.168.0.170.pub</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">这样</span>147<span style="font-family: 宋体;">上</span>root<span style="font-family: 宋体;">用户就信任了来自</span>170<span style="font-family: 宋体;">的</span>root<span style="font-family: 宋体;">用户通信。在</span>170<span style="font-family: 宋体;">，往</span>147<span style="font-family: 宋体;">上</span>scp<span style="font-family: 宋体;">、</span>ssh<span style="font-family: 宋体;">、</span>rsync<span style="font-family: 宋体;">都是免密码了。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2009/316_linux-ssh-trust.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++设计模式-代理</title>
		<link>http://www.shenmiguo.com/archives/2009/314_design-patterns-proxy.html</link>
		<comments>http://www.shenmiguo.com/archives/2009/314_design-patterns-proxy.html#comments</comments>
		<pubDate>Thu, 17 Sep 2009 08:58:33 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[代理]]></category>
		<category><![CDATA[设计模式]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=314</guid>
		<description><![CDATA[定义 代理（Proxy）模式，为其他对象提供一种代理以控制对这个对象的访问。 &#160; 结构 &#160; 理解 1.&#160;&#160;&#160;&#160;&#160;&#160; Subject定义了RealSubject和Proxy的公用接口，使得任何调用RealSubject的地方都可以调用Proxy。 2.&#160;&#160;&#160;&#160;&#160;&#160; RealSubject是代理的实体类。 3.&#160;&#160;&#160;&#160;&#160;&#160; Proxy保存一直指向代理实体（RealSubject）的指针。Proxy与Subject的接口相同，代理就可以替代实体；Proxy负责RealSubject的创建和管理。 &#160; 要点 1.&#160;&#160;&#160;&#160;&#160;&#160; 根据代理模式效果的不同，有如下几种代理应用： 远程代理（Remote Proxy） 为一个位于不同的地址空间的对象提供隐藏实现。这个不同的地址空间可以是在本机器中，也可是在另一台机器中。远程代理又叫做大使（Ambassador）。 远程调用和webservice服务就是典型的远程代理模式，客户并不知道网络访问细节（访问本地还是远程网络），代理对象对外屏蔽了网络通讯细则。 &#160; 虚拟代理（Virtual Proxy） 根据需要创建一个资源消耗较大的对象，使得此对象只在需要时才会被真正创建。使用虚拟代理模式的好处就是代理对象可以在必要的时候才将被代理的对象加载；代理可以对加载的过程加以必要的优化。 文档中有非常大的图片，为了保证文档打开速度，在打开文档的时候并不真正创建图片对象，只有当用到图片的时候，才会去创建图片对象。 &#160; 写时拷贝代理（Copy-on-write Proxy） 写时拷贝是虚拟代理的一种特殊应用,可以大幅降低拷贝大对象的开销。写时拷贝可以延迟一个对象的拷贝操作到客户调用里。一般来说，对象的深度拷贝是一个高开销的动作，该代理可以让这个动作延迟，只有对象被修改的时候才被拷贝一份。 Linux创建进程就用到了Copy-on-write。fork派生子进程的时候，若子进程拷贝父进程的整个地址空间，会使得创建进程的速度非常慢而且效率低下。而实事上，子进程几乎不必读和修改父进程所拥有的资源， Copy-on-write允许父子进程拥有相同的物理页，只有两者中有一个试图修改一个物理页时，内核就把要修改的物理页内容拷贝到一个新的物理页，并把这个新的物理页地址分配给正在写的进程。 &#160; 保护代理（Protection Proxy） 控制对RealSubject对象的访问。可以实现给不同的用户提供不同级别的使用权限。保护代理可以在运行时间对用户的有关权限进行检查，然后在核实后决定将调用传递给被代理的对象。 &#160; 智能引用代理（Smart Reference Proxy） 取代了简单的指针(-&#62;, *)，在对象访问时提供一些附加操作：对指向实际对象的引用计数，引用计数为0时，可以自动释放资源（智能指针）；当第一次引用一个持久的对象，将它装入内存；在访问一个实际对象前，检查是否已经锁定了它，以确保其他对象不能改变它。 &#160; 缓存代理（Cache Proxy） 为创建时高开销的对象提供缓存，以供多客户端共享。如数据库代理，客户端进行Sql查询时，并不访问数据库，而是通过与数据库代理之间进行交互，如果数据库代理中没有缓存数据，才真正去数据库查询。 &#160; 防火墙代理（Firewall Proxy） 保护目标对象不受某些不良客户端的侵害。 &#160; 同步代理（Synchronization Proxy） 使几个用户能够同时使用一个对象而没有冲突，提供并发控制。 &#160; 2.&#160;&#160;&#160;&#160;&#160;&#160; [...]]]></description>
			<content:encoded><![CDATA[<div style="line-height:150%"><b><span style="font-size:12.0pt;line-height:150%;font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">定义</span></b></div>
<div style="line-height:150%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">代理（</span>Proxy<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）模式，为其他对象提供一种代理以控制对这个对象的访问。</span></div>
<div style="line-height:150%">&nbsp;<span id="more-314"></span></div>
<div style="line-height:150%"><b><span style="font-size:12.0pt;line-height:150%;font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">结构</span></b></div>
<div align="center" style="text-align:center;line-height:150%"><img alt="proxy" title="proxy" width="389" height="244" class="aligncenter size-full wp-image-315" src="http://www.shenmiguo.com/wp-content/uploads/2009/09/proxy.jpg" /></div>
<div style="line-height:150%">&nbsp;</div>
<div style="line-height:150%"><b><span style="font-size:12.0pt;line-height:150%;font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">理解</span></b></div>
<div style="margin-left:18.0pt;text-indent:-18.0pt;line-height:<br />
150%;"><span style="Times New Roman&quot;">1.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Subject<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">定义了</span>RealSubject<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>Proxy<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的公用接口，使得任何调用</span>RealSubject<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的地方都可以调用</span>Proxy<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></div>
<div style="margin-left:18.0pt;text-indent:-18.0pt;line-height:<br />
150%;"><span style="Times New Roman&quot;">2.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>RealSubject<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">是代理的实体类。</span></div>
<div style="margin-left:18.0pt;text-indent:-18.0pt;line-height:<br />
150%;"><span style="Times New Roman&quot;">3.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Proxy<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">保存一直指向代理实体（</span>RealSubject<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）的指针。</span>Proxy<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">与</span>Subject<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的接口相同，代理就可以替代实体；</span>Proxy<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">负责</span>RealSubject<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的创建和管理。</span></div>
<div style="line-height:150%">&nbsp;</div>
<div style="line-height:150%"><b><span style="font-size:12.0pt;line-height:150%;font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">要点</span></b></div>
<div style="margin-left:18.0pt;text-indent:-18.0pt;line-height:<br />
150%;"><span style="Times New Roman&quot;">1.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">根据代理模式效果的不同，有如下几种代理应用：</span></div>
<div style="margin-left:18.0pt;line-height:150%"><b><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">远程代理（</span>Remote Proxy</b><b><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span></b></div>
<div style="margin-left:18.0pt;line-height:150%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为一个位于不同的地址空间的对象提供隐藏实现。这个不同的地址空间可以是在本机器中，也可是在另一台机器中。远程代理又叫做大使（</span>Ambassador<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）。</span></div>
<div style="margin-left:18.0pt;line-height:150%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">远程调用和</span>webservice<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">服务就是典型的远程代理模式，客户并不知道网络访问细节（访问本地还是远程网络），代理对象对外屏蔽了网络通讯细则。</span></div>
<div style="margin-left:18.0pt;line-height:150%">&nbsp;</div>
<div style="margin-left:18.0pt;line-height:150%"><b><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">虚拟代理（</span>Virtual Proxy</b><b><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span></b></div>
<div style="margin-left:18.0pt;line-height:150%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">根据需要创建一个资源消耗较大的对象，使得此对象只在需要时才会被真正创建。使用虚拟代理模式的好处就是代理对象可以在必要的时候才将被代理的对象加载；代理可以对加载的过程加以必要的优化。</span></div>
<div style="margin-left:18.0pt;line-height:150%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文档中有非常大的图片，为了保证文档打开速度，在打开文档的时候并不真正创建图片对象，只有当用到图片的时候，才会去创建图片对象。</span></div>
<div style="margin-left:18.0pt;line-height:150%">&nbsp;</div>
<div style="margin-left:18.0pt;line-height:150%"><b><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">写时拷贝代理（</span>Copy-on-write Proxy</b><b><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span></b></div>
<div style="margin-left:18.0pt;line-height:150%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">写时拷贝是虚拟代理的一种特殊应用</span>,<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">可以大幅降低拷贝大对象的开销。写时拷贝可以延迟一个对象的拷贝操作到客户调用里。一般来说，对象的深度拷贝是一个高开销的动作，该代理可以让这个动作延迟，只有对象被修改的时候才被拷贝一份。</span></div>
<div style="margin-left:18.0pt;line-height:150%">Linux<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">创建进程就用到了</span>Copy-on-write<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span>fork<span style="font-family:<br />
宋体;Times New Roman&quot;;Times New Roman&quot;">派生子进程的时候，若子进程拷贝父进程的整个地址空间，会使得创建进程的速度非常慢而且效率低下。而实事上，子进程几乎不必读和修改父进程所拥有的资源，</span> Copy-on-write<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">允许父子进程拥有相同的物理页，只有两者中有一个试图修改一个物理页时，内核就把要修改的物理页内容拷贝到一个新的物理页，并把这个新的物理页地址分配给正在写的进程。</span></div>
<div style="margin-left:18.0pt;line-height:150%">&nbsp;</div>
<div style="margin-left:18.0pt;line-height:150%"><b><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">保护代理（</span>Protection Proxy</b><b><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span></b></div>
<div style="margin-left:18.0pt;line-height:150%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">控制对</span>RealSubject<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">对象的访问。可以实现给不同的用户提供不同级别的使用权限。保护代理可以在运行时间对用户的有关权限进行检查，然后在核实后决定将调用传递给被代理的对象。</span></div>
<div style="margin-left:18.0pt;line-height:150%">&nbsp;</div>
<div style="margin-left:18.0pt;line-height:150%"><b><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">智能引用代理（</span>Smart Reference Proxy</b><b><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span></b></div>
<div style="margin-left:18.0pt;line-height:150%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">取代了简单的指针</span>(-&gt;, *)<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，在对象访问时提供一些附加操作：对指向实际对象的引用计数，引用计数为</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时，可以自动释放资源（智能指针）；当第一次引用一个持久的对象，将它装入内存；在访问一个实际对象前，检查是否已经锁定了它，以确保其他对象不能改变它。</span></div>
<div style="margin-left:18.0pt;line-height:150%">&nbsp;</div>
<div style="margin-left:18.0pt;line-height:150%"><b><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">缓存代理（</span>Cache Proxy</b><b><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span></b></div>
<div style="margin-left:18.0pt;line-height:150%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为创建时高开销的对象提供缓存，以供多客户端共享。如数据库代理，客户端进行</span>Sql<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">查询时，并不访问数据库，而是通过与数据库代理之间进行交互，如果数据库代理中没有缓存数据，才真正去数据库查询。</span></div>
<div style="margin-left:18.0pt;line-height:150%">&nbsp;</div>
<div style="margin-left:18.0pt;line-height:150%"><b><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">防火墙代理（</span>Firewall Proxy</b><b><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span></b></div>
<div style="margin-left:18.0pt;line-height:150%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">保护目标对象不受某些不良客户端的侵害。</span></div>
<div style="margin-left:18.0pt;line-height:150%">&nbsp;</div>
<div style="margin-left:18.0pt;line-height:150%"><b><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">同步代理（</span>Synchronization Proxy</b><b><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span></b></div>
<div style="margin-left:18.0pt;line-height:150%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">使几个用户能够同时使用一个对象而没有冲突，提供并发控制。</span></div>
<div style="margin-left:18.0pt;line-height:150%">&nbsp;</div>
<div style="margin-left:18.0pt;text-indent:-18.0pt;line-height:<br />
150%;"><span style="Times New Roman&quot;">2.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>C++<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">语言可通过重载</span>-&gt;<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">和</span>*<span style="font-family:<br />
宋体;Times New Roman&quot;;Times New Roman&quot;">运算符实现类的代理。</span></div>
<div style="margin-left:18.0pt;line-height:150%">Image* ImagePtr::operator-&gt; () {</div>
<div style="margin-left:18.0pt;line-height:150%"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return LoadImage(); //</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">装载对象并返回对象指针</span></div>
<div style="margin-left:18.0pt;line-height:150%">}</div>
<div style="margin-left:18.0pt;line-height:150%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这样对象被引用时，就装载对象，起到了代理的作用。但这种方式的问题是，只要引用就加载，而不能指定在调用某个方法（如</span>Draw<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）的时候才加载。</span></div>
<div style="line-height:150%">&nbsp;</div>
<div style="line-height:150%"><b><span style="font-size:12.0pt;line-height:150%;font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">应用</span></b></div>
<div style="line-height:150%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">每种代理模式的应用场景都非常之多。共同点是代理起到了客户端与真实对象之间中间层的作用。通过对中间层进行改造，到达各种指责目的。</span></div>
<div style="line-height:150%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">源码通过缓存代理应用来举例说明。</span></div>
<div style="line-height:150%">&nbsp;</div>
<div style="line-height:150%"><b><span style="font-size:12.0pt;line-height:150%;font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">源码</span></b></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;color:blue;">#include</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;"> <span style="color:#A31515">&lt;iostream&gt;</span></span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;color:blue;">#include</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;"> <span style="color:#A31515">&lt;string&gt;</span></span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;color:blue;">#include</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;"> <span style="color:#A31515">&lt;map&gt;</span></span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;color:blue;">using</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;"> <span style="color:blue">namespace</span> <span style="color:#010001">std</span>;</span></div>
<div align="left" style="text-align:left;text-autospace:none">&nbsp;</div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;color:green;">//</span><span style="font-size:9.0pt;font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;;<br />
color:green;">代理抽象基类</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;color:blue;">class</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;"> <span style="color:#010001">CProxy</span></span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">{</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;color:blue;">public</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;">:</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:#010001">CProxy</span>() {};</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:blue">virtual</span> ~<span style="color:#010001">CProxy</span>() {};</span></div>
<div align="left" style="text-align:left;text-autospace:none">&nbsp;</div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:blue">virtual</span> <span style="color:#010001">string</span> <span style="color:#010001">Get</span>(<span style="color:blue">const</span> <span style="color:#010001">string</span> &amp;<span style="color:#010001">strKey</span>) = 0;</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">};</span></div>
<div align="left" style="text-align:left;text-autospace:none">&nbsp;</div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;color:green;">//</span><span style="font-size:9.0pt;font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;;<br />
color:green;">代理的实际目标</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;color:blue;">class</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;"> <span style="color:#010001">CDataServer</span> : <span style="color:blue">public</span> <span style="color:#010001">CProxy</span></span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">{</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;color:blue;">public</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;">:</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:#010001">CDataServer</span>() {};</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:blue">virtual</span> ~<span style="color:#010001">CDataServer</span>() {};</span></div>
<div align="left" style="text-align:left;text-autospace:none">&nbsp;</div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:blue">virtual</span> <span style="color:#010001">string</span> <span style="color:#010001">Get</span>(<span style="color:blue">const</span> <span style="color:#010001">string</span> &amp;<span style="color:#010001">strKey</span>)</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; {</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green">//TODO: query db here&#8230;</span></span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#010001">cout</span> &lt;&lt; <span style="color:#A31515">&quot;real server query db&#8230;&quot;</span> &lt;&lt; <span style="color:#010001">endl</span>;</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue">return</span> <span style="color:#010001">strKey</span> + <span style="color:#010001">strKey</span>;</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; }</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">};</span></div>
<div align="left" style="text-align:left;text-autospace:none">&nbsp;</div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;color:green;">//</span><span style="font-size:9.0pt;font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;;<br />
color:green;">代理类</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;color:blue;">class</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;"> <span style="color:#010001">CCacheProxy</span> : <span style="color:blue">public</span> <span style="color:#010001">CProxy</span></span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">{</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;color:blue;">public</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;">:</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:#010001">CCacheProxy</span>() : <span style="color:#010001">m_dataServer</span>(<span style="color:blue">new</span> <span style="color:#010001">CDataServer</span>)</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; {};</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:blue">virtual</span> ~<span style="color:#010001">CCacheProxy</span>() </span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; {</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue">delete</span> <span style="color:#010001">m_dataServer</span>;</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; };</span></div>
<div align="left" style="text-align:left;text-autospace:none">&nbsp;</div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:blue">virtual</span> <span style="color:#010001">string</span> <span style="color:#010001">Get</span>(<span style="color:blue">const</span> <span style="color:#010001">string</span> &amp;<span style="color:#010001">strKey</span>)</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; {</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green">//target cache </span></span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#010001">map</span>&lt;<span style="color:#010001">string</span>, <span style="color:#010001">string</span>&gt;::<span style="color:#010001">iterator</span> <span style="color:#010001">itr</span> = <span style="color:#010001">m_mapValue</span>.<span style="color:#010001">find</span>(<span style="color:#010001">strKey</span>);</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue">if</span> (<span style="color:#010001">itr</span> != <span style="color:#010001">m_mapValue</span>.<span style="color:#010001">end</span>())</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#010001">cout</span> &lt;&lt; <span style="color:#A31515">&quot;target cache&#8230;&quot;</span> &lt;&lt; <span style="color:#010001">endl</span>;</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue">return</span> <span style="color:#010001">itr</span>-&gt;<span style="color:#010001">second</span>;</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></div>
<div align="left" style="text-align:left;text-autospace:none">&nbsp;</div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green">//request from real server</span></span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#010001">string</span> <span style="color:#010001">strVal</span> = <span style="color:#010001">m_dataServer</span>-&gt;<span style="color:#010001">Get</span>(<span style="color:#010001">strKey</span>);</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#010001">m_mapValue</span>[<span style="color:#010001">strKey</span>] = <span style="color:#010001">strVal</span>;</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue">return</span> <span style="color:#010001">strVal</span>;</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; }</span></div>
<div align="left" style="text-align:left;text-autospace:none">&nbsp;</div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;color:blue;">protected</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;">:</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:#010001">CDataServer</span>*&nbsp;&nbsp;&nbsp; <span style="color:#010001">m_dataServer</span>;</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:#010001">map</span>&lt;<span style="color:#010001">string</span>, <span style="color:#010001">string</span>&gt; <span style="color:#010001">m_mapValue</span>; <span style="color:green">//cache</span></span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">};</span></div>
<div align="left" style="text-align:left;text-autospace:none">&nbsp;</div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;color:blue;">int</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;"> <span style="color:#010001">main</span>()</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">{</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:green">//client</span></span><span style="font-size:9.0pt;font-family:宋体;Courier New&quot;;Courier New&quot;;Courier New&quot;;<br />
color:green;">并不知道</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:green;">CDataServer</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:#010001">CProxy</span>* <span style="color:#010001">p</span> = <span style="color:blue">new</span> <span style="color:#010001">CCacheProxy</span>;</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:#010001">string</span> <span style="color:#010001">strKey</span> = <span style="color:#A31515">&quot;ab&quot;</span>;</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:#010001">string</span> <span style="color:#010001">strVal</span> = <span style="color:#010001">p</span>-&gt;<span style="color:#010001">Get</span>(<span style="color:#010001">strKey</span>);</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:#010001">cout</span> &lt;&lt; <span style="color:#A31515">&quot;key: &quot;</span> &lt;&lt; <span style="color:#010001">strKey</span> &lt;&lt; <span style="color:#A31515">&quot;, value: &quot;</span> &lt;&lt; <span style="color:#010001">strVal</span> &lt;&lt; <span style="color:#010001">endl</span>;</span></div>
<div align="left" style="text-align:left;text-autospace:none">&nbsp;</div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:#010001">strKey</span> = <span style="color:#A31515">&quot;abcd&quot;</span>;</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:#010001">strVal</span> = <span style="color:#010001">p</span>-&gt;<span style="color:#010001">Get</span>(<span style="color:#010001">strKey</span>);</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:#010001">cout</span> &lt;&lt; <span style="color:#A31515">&quot;key: &quot;</span> &lt;&lt; <span style="color:#010001">strKey</span> &lt;&lt; <span style="color:#A31515">&quot;, value: &quot;</span> &lt;&lt; <span style="color:#010001">strVal</span> &lt;&lt; <span style="color:#010001">endl</span>;</span></div>
<div align="left" style="text-align:left;text-autospace:none">&nbsp;</div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:#010001">strKey</span> = <span style="color:#A31515">&quot;ab&quot;</span>;</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:#010001">strVal</span> = <span style="color:#010001">p</span>-&gt;<span style="color:#010001">Get</span>(<span style="color:#010001">strKey</span>);</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:#010001">cout</span> &lt;&lt; <span style="color:#A31515">&quot;key: &quot;</span> &lt;&lt; <span style="color:#010001">strKey</span> &lt;&lt; <span style="color:#A31515">&quot;, value: &quot;</span> &lt;&lt; <span style="color:#010001">strVal</span> &lt;&lt; <span style="color:#010001">endl</span>;</span></div>
<div align="left" style="text-align:left;text-autospace:none">&nbsp;</div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color:blue">return</span> 0;</span></div>
<div align="left" style="text-align:left;text-autospace:none"><span style="font-size:9.0pt;font-family:<br />
&quot;Courier New&quot;;">}</span></div>
<div style="line-height:150%">&nbsp;</div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2009/314_design-patterns-proxy.html/feed</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>C++设计模式-享元</title>
		<link>http://www.shenmiguo.com/archives/2009/311_design-patterns-flyweight.html</link>
		<comments>http://www.shenmiguo.com/archives/2009/311_design-patterns-flyweight.html#comments</comments>
		<pubDate>Wed, 16 Sep 2009 03:22:56 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[flyweight]]></category>
		<category><![CDATA[享元]]></category>
		<category><![CDATA[组合]]></category>
		<category><![CDATA[设计模式]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=311</guid>
		<description><![CDATA[定义 享元（Flyweight）模式是指，运用共享技术有效地支持大量细粒度的对象。 &#160; 结构 &#160; 理解 1.&#160;&#160;&#160;&#160;&#160;&#160; Flyweight是享元抽象基类。Flyweight::Operation是公共接口，享元依赖的外部状态（ExtrinsicState）通过接口参数传入。 2.&#160;&#160;&#160;&#160;&#160;&#160; ConcreteFlyweight是具体享元类。具体享元必须是可共享的，必须为内部状态（IntrinsicState）提供存储空间。 3.&#160;&#160;&#160;&#160;&#160;&#160; UnshareConcreteFlyweight是不可共享的具体享元，也叫做复合享元。复合享元是由单纯具体享元通过复合（Composite）模式而成的，将若干个具体享元作为子节点。 4.&#160;&#160;&#160;&#160;&#160;&#160; FlyweightFactory是享元工厂。创建并管理享元对象。当Client请求一个享元对象时，FlyweightFactory返回一个已创建的享元对象（如果没有就先创建）。 5.&#160;&#160;&#160;&#160;&#160;&#160; Client维护一个指向Flyweight的指针，并且存储Flyweight的外部状态。 &#160; 要点 1.&#160;&#160;&#160;&#160;&#160;&#160; 一个应用程序使用了大量相同的对象。对于相同的对象只需要共享一份就可以了。如文本文档中字符对象就会大量存在，如果不使用享元模式，就要使用大量的对象，将会耗费大量的存储开销。 2.&#160;&#160;&#160;&#160;&#160;&#160; 对于文本文档的字符对象，字符代码是内部状态，字体字号大小排版位置等是外部状态。对象的大多数状态都可变为外部状态。 3.&#160;&#160;&#160;&#160;&#160;&#160; 外部状态可以由一个单独的外部对象来存储。如文本文档，外部对象存储文档的排版信息。 &#160; 应用 用文本文档来说明享元模式的应用。 源码中没有演示不可共享的具体享元。可通过引入行对象（Row），将Character作为Row的子节点来实现，Row就是不可共享的享元。 &#160; 源码 #include &#60;iostream&#62; #include &#60;string&#62; #include &#60;vector&#62; #include &#60;map&#62; using namespace std; &#160; //外部状态. 存放字体大小和位置 class CContext { public: &#160;&#160;&#160; CContext() : m_iIdx(0) {}; &#160;&#160;&#160; void [...]]]></description>
			<content:encoded><![CDATA[<p><b><span style="font-size: 12pt; line-height: 150%; font-family: 宋体;">定义</span></b></p>
<div style="line-height: 150%;"><span style="font-family: 宋体;">享元（</span>Flyweight<span style="font-family: 宋体;">）模式是指，运用共享技术有效地支持大量细粒度的对象。</span></div>
<div style="line-height: 150%;"><span style="font-family: 宋体;"><span id="more-311"></span></span></div>
<div style="line-height: 150%;">&nbsp;</div>
<div style="line-height: 150%;"><b><span style="font-size: 12pt; line-height: 150%; font-family: 宋体;">结构</span></b></div>
<div align="center" style="text-align: center; line-height: 150%;"><img width="497" height="292" class="aligncenter size-full wp-image-312" title="flyweight" alt="flyweight" src="http://www.shenmiguo.com/wp-content/uploads/2009/09/flyweight.jpg" /></div>
<div style="line-height: 150%;">&nbsp;</div>
<div style="line-height: 150%;"><b><span style="font-size: 12pt; line-height: 150%; font-family: 宋体;">理解</span></b></div>
<div style="margin-left: 18pt; text-indent: -18pt; line-height: 150%;"><span>1.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Flyweight<span style="font-family: 宋体;">是享元抽象基类。</span>Flyweight::Operation<span style="font-family: 宋体;">是公共接口，享元依赖的外部状态（</span>ExtrinsicState<span style="font-family: 宋体;">）通过接口参数传入。</span></div>
<div style="margin-left: 18pt; text-indent: -18pt; line-height: 150%;"><span>2.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>ConcreteFlyweight<span style="font-family: 宋体;">是<span style="color: red;">具体享元</span>类。具体享元必须是可共享的，必须为内部状态（</span>IntrinsicState<span style="font-family: 宋体;">）提供存储空间。</span></div>
<div style="margin-left: 18pt; text-indent: -18pt; line-height: 150%;"><span>3.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>UnshareConcreteFlyweight<span style="font-family: 宋体;">是不可共享的具体享元，也叫做<span style="color: red;">复合享元</span>。复合享元是由单纯具体享元通过复合（</span>Composite<span style="font-family: 宋体;">）模式而成的，将若干个具体享元作为子节点。</span></div>
<div style="margin-left: 18pt; text-indent: -18pt; line-height: 150%;"><span>4.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>FlyweightFactory<span style="font-family: 宋体;">是享元工厂。创建并管理享元对象。当</span>Client<span style="font-family: 宋体;">请求一个享元对象时，</span>FlyweightFactory<span style="font-family: 宋体;">返回一个已创建的享元对象（如果没有就先创建）。</span></div>
<div style="margin-left: 18pt; text-indent: -18pt; line-height: 150%;"><span>5.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Client<span style="font-family: 宋体;">维护一个指向</span>Flyweight<span style="font-family: 宋体;">的指针，并且存储</span>Flyweight<span style="font-family: 宋体;">的外部状态。</span></div>
<div style="line-height: 150%;">&nbsp;</div>
<div style="line-height: 150%;"><b><span style="font-size: 12pt; line-height: 150%; font-family: 宋体;">要点</span></b></div>
<div style="margin-left: 18pt; text-indent: -18pt; line-height: 150%;"><span>1.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family: 宋体;">一个应用程序使用了大量相同的对象。对于相同的对象只需要共享一份就可以了。如<span style="color: red;">文本文档</span>中<span style="color: red;">字符对象</span>就会大量存在，如果不使用享元模式，就要使用大量的对象，将会耗费大量的存储开销。</span></div>
<div style="margin-left: 18pt; text-indent: -18pt; line-height: 150%;"><span>2.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family: 宋体;">对于文本文档的<span style="color: red;">字符对象</span>，字符代码是内部状态，字体字号大小排版位置等是外部状态。对象的大多数状态都可变为外部状态。</span></div>
<div style="margin-left: 18pt; text-indent: -18pt; line-height: 150%;"><span>3.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family: 宋体;">外部状态可以由一个单独的外部对象来存储。如文本文档，外部对象存储文档的排版信息。</span></div>
<div style="line-height: 150%;">&nbsp;</div>
<div style="line-height: 150%;"><b><span style="font-size: 12pt; line-height: 150%; font-family: 宋体;">应用</span></b></div>
<div style="line-height: 150%;"><span style="font-family: 宋体;">用文本文档来说明享元模式的应用。</span></div>
<div style="line-height: 150%;"><span style="font-family: 宋体;">源码中没有演示不可共享的具体享元。可通过引入行对象（</span>Row<span style="font-family: 宋体;">），将</span>Character<span style="font-family: 宋体;">作为</span>Row<span style="font-family: 宋体;">的子节点来实现，</span>Row<span style="font-family: 宋体;">就是不可共享的享元。</span></div>
<div style="line-height: 150%;">&nbsp;</div>
<div style="line-height: 150%;"><b><span style="font-size: 12pt; line-height: 150%; font-family: 宋体;">源码</span></b></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">#include</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: rgb(163, 21, 21);">&lt;iostream&gt;</span></span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">#include</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: rgb(163, 21, 21);">&lt;string&gt;</span></span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">#include</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: rgb(163, 21, 21);">&lt;vector&gt;</span></span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">#include</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: rgb(163, 21, 21);">&lt;map&gt;</span></span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">using</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: blue;">namespace</span> <span style="color: rgb(1, 0, 1);">std</span>;</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: green;">//</span><span style="font-size: 9pt; font-family: 宋体; color: green;">外部状态</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: green;">. </span><span style="font-size: 9pt; font-family: 宋体; color: green;">存放字体大小和位置</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">class</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: rgb(1, 0, 1);">CContext</span></span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">{</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">public</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">:</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">CContext</span>() : <span style="color: rgb(1, 0, 1);">m_iIdx</span>(0) {};</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">void</span> <span style="color: rgb(1, 0, 1);">AppendFontSize</span>(<span style="color: blue;">const</span> <span style="color: blue;">int</span> <span style="color: rgb(1, 0, 1);">iFontSize</span>)</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; {</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">m_vecFontSize</span>.<span style="color: rgb(1, 0, 1);">push_back</span>(<span style="color: rgb(1, 0, 1);">iFontSize</span>);</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; }</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">int</span> <span style="color: rgb(1, 0, 1);">GetCharSize</span>()</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; {</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> <span style="color: rgb(1, 0, 1);">m_vecFontSize</span>[<span style="color: rgb(1, 0, 1);">m_iIdx</span>];</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; }</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">int</span> <span style="color: rgb(1, 0, 1);">GetCharIdx</span>()</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; {</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> <span style="color: rgb(1, 0, 1);">m_iIdx</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; }</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">void</span> <span style="color: rgb(1, 0, 1);">Next</span>()</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; {</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">m_iIdx</span>++;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; }</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">private</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">:</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">int</span> <span style="color: rgb(1, 0, 1);">m_iIdx</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">vector</span>&lt;<span style="color: blue;">int</span>&gt; <span style="color: rgb(1, 0, 1);">m_vecFontSize</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">};</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: green;">//Flyweight</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">class</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: rgb(1, 0, 1);">CFlyweight</span></span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">{</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">public</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">:</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">CFlyweight</span>(){};</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">virtual</span> ~<span style="color: rgb(1, 0, 1);">CFlyweight</span>(){};</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: green;">//</span></span><span style="font-size: 9pt; font-family: 宋体; color: green;">享元方法，</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: green;">context</span><span style="font-size: 9pt; font-family: 宋体; color: green;">是外部状态，通过参数传入</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">virtual</span> <span style="color: blue;">void</span> <span style="color: rgb(1, 0, 1);">ShowInfo</span>(<span style="color: rgb(1, 0, 1);">CContext</span> &amp;<span style="color: rgb(1, 0, 1);">context</span>) = 0;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">};</span></div>
<div align="left">&nbsp;</div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: green;">//ConcreteFlyweight</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">class</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: rgb(1, 0, 1);">CCharacter</span> : <span style="color: blue;">public</span> <span style="color: rgb(1, 0, 1);">CFlyweight</span></span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">{</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">public</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">:</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">CCharacter</span>(<span style="color: blue;">const</span> <span style="color: blue;">char</span> <span style="color: rgb(1, 0, 1);">c</span>) : <span style="color: rgb(1, 0, 1);">m_c</span>(<span style="color: rgb(1, 0, 1);">c</span>) {};</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">virtual</span> <span style="color: blue;">void</span> <span style="color: rgb(1, 0, 1);">ShowInfo</span>(<span style="color: rgb(1, 0, 1);">CContext</span> &amp;<span style="color: rgb(1, 0, 1);">context</span>)</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; {</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">cout</span> &lt;&lt; <span style="color: rgb(163, 21, 21);">&quot;IntrinsicState: char=&quot;</span> &lt;&lt; <span style="color: rgb(1, 0, 1);">m_c</span> &lt;&lt; <span style="color: rgb(163, 21, 21);">&quot;; ExtrinsicState: index=&quot;</span> &lt;&lt; <span style="color: rgb(1, 0, 1);">context</span>.<span style="color: rgb(1, 0, 1);">GetCharIdx</span>() &lt;&lt; <span style="color: rgb(163, 21, 21);">&quot;, size=&quot;</span> &lt;&lt; <span style="color: rgb(1, 0, 1);">context</span>.<span style="color: rgb(1, 0, 1);">GetCharSize</span>() &lt;&lt; <span style="color: rgb(1, 0, 1);">endl</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">context</span>.<span style="color: rgb(1, 0, 1);">Next</span>();</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; };</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">protected</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">:</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">char</span> <span style="color: rgb(1, 0, 1);">m_c</span>; <span style="color: green;">//</span></span><span style="font-size: 9pt; font-family: 宋体; color: green;">内部状态</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">};</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: green;">//FlyweightFactory. </span><span style="font-size: 9pt; font-family: 宋体; color: green;">可用单件模式</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: green;">. </span><span style="font-size: 9pt; font-family: 宋体; color: green;">不考虑释放资源</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">class</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: rgb(1, 0, 1);">CFlyweightFactory</span></span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">{</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">public</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">:</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">CFlyweight</span>* <span style="color: rgb(1, 0, 1);">GetFlyweight</span>(<span style="color: blue;">const</span> <span style="color: blue;">char</span> <span style="color: rgb(1, 0, 1);">c</span>)</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; {</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">map</span>&lt;<span style="color: blue;">char</span>, <span style="color: rgb(1, 0, 1);">CFlyweight</span>*&gt;::<span style="color: rgb(1, 0, 1);">iterator</span> <span style="color: rgb(1, 0, 1);">itr</span> = <span style="color: rgb(1, 0, 1);">m_mapPool</span>.<span style="color: rgb(1, 0, 1);">find</span>(<span style="color: rgb(1, 0, 1);">c</span>);</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span> (<span style="color: rgb(1, 0, 1);">itr</span> != <span style="color: rgb(1, 0, 1);">m_mapPool</span>.<span style="color: rgb(1, 0, 1);">end</span>())</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">cout</span> &lt;&lt; <span style="color: rgb(1, 0, 1);">c</span> &lt;&lt; <span style="color: rgb(163, 21, 21);">&quot; already exists.&quot;</span> &lt;&lt; <span style="color: rgb(1, 0, 1);">endl</span>; </span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> <span style="color: rgb(1, 0, 1);">itr</span>-&gt;<span style="color: rgb(1, 0, 1);">second</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">cout</span> &lt;&lt; <span style="color: rgb(1, 0, 1);">c</span> &lt;&lt; <span style="color: rgb(163, 21, 21);">&quot; added.&quot;</span> &lt;&lt; <span style="color: rgb(1, 0, 1);">endl</span>; </span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">CFlyweight</span>* <span style="color: rgb(1, 0, 1);">p</span> = <span style="color: blue;">new</span> <span style="color: rgb(1, 0, 1);">CCharacter</span>(<span style="color: rgb(1, 0, 1);">c</span>);</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">m_mapPool</span>[<span style="color: rgb(1, 0, 1);">c</span>] = <span style="color: rgb(1, 0, 1);">p</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> <span style="color: rgb(1, 0, 1);">p</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; };</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">private</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">:</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">map</span>&lt;<span style="color: blue;">char</span>, <span style="color: rgb(1, 0, 1);">CFlyweight</span>*&gt; <span style="color: rgb(1, 0, 1);">m_mapPool</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">};</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">int</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: rgb(1, 0, 1);">main</span>()</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">{</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">CFlyweightFactory</span> <span style="color: rgb(1, 0, 1);">factory</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">CContext</span> <span style="color: rgb(1, 0, 1);">context</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">CFlyweight</span>* <span style="color: rgb(1, 0, 1);">p</span> = <span style="color: rgb(1, 0, 1);">NULL</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">p</span> = <span style="color: rgb(1, 0, 1);">factory</span>.<span style="color: rgb(1, 0, 1);">GetFlyweight</span>(<span style="color: rgb(163, 21, 21);">&#8216;a&#8217;</span>);</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">context</span>.<span style="color: rgb(1, 0, 1);">AppendFontSize</span>(8);</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">p</span>-&gt;<span style="color: rgb(1, 0, 1);">ShowInfo</span>(<span style="color: rgb(1, 0, 1);">context</span>);</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">p</span> = <span style="color: rgb(1, 0, 1);">factory</span>.<span style="color: rgb(1, 0, 1);">GetFlyweight</span>(<span style="color: rgb(163, 21, 21);">&#8216;b&#8217;</span>);</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">context</span>.<span style="color: rgb(1, 0, 1);">AppendFontSize</span>(9);</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">p</span>-&gt;<span style="color: rgb(1, 0, 1);">ShowInfo</span>(<span style="color: rgb(1, 0, 1);">context</span>);</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">p</span> = <span style="color: rgb(1, 0, 1);">factory</span>.<span style="color: rgb(1, 0, 1);">GetFlyweight</span>(<span style="color: rgb(163, 21, 21);">&#8216;c&#8217;</span>);</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">context</span>.<span style="color: rgb(1, 0, 1);">AppendFontSize</span>(10);</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">p</span>-&gt;<span style="color: rgb(1, 0, 1);">ShowInfo</span>(<span style="color: rgb(1, 0, 1);">context</span>);</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">p</span> = <span style="color: rgb(1, 0, 1);">factory</span>.<span style="color: rgb(1, 0, 1);">GetFlyweight</span>(<span style="color: rgb(163, 21, 21);">&#8216;b&#8217;</span>);</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">context</span>.<span style="color: rgb(1, 0, 1);">AppendFontSize</span>(11);</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">p</span>-&gt;<span style="color: rgb(1, 0, 1);">ShowInfo</span>(<span style="color: rgb(1, 0, 1);">context</span>);</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> 0;</span></div>
<div style="line-height: 150%;"><span style="font-size: 9pt; line-height: 150%; font-family: &quot;Courier New&quot;;">}</span></div>
<div style="line-height: 150%;">&nbsp;</div>
<div style="line-height: 150%;"><span style="font-family: 宋体;">输出：</span></div>
<div style="line-height: 150%;">a added.</div>
<div style="line-height: 150%;">IntrinsicState: char=a; ExtrinsicState: index=0, size=8</div>
<div style="line-height: 150%;">b added.</div>
<div style="line-height: 150%;">IntrinsicState: char=b; ExtrinsicState: index=1, size=9</div>
<div style="line-height: 150%;">c added.</div>
<div style="line-height: 150%;">IntrinsicState: char=c; ExtrinsicState: index=2, size=10</div>
<div style="line-height: 150%;">b already exists.</div>
<div style="line-height: 150%;">IntrinsicState: char=b; ExtrinsicState: index=3, size=11</div>
<div style="line-height: 150%;">&nbsp;</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2009/311_design-patterns-flyweight.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++设计模式-外观</title>
		<link>http://www.shenmiguo.com/archives/2009/308_design-patterns-facade.html</link>
		<comments>http://www.shenmiguo.com/archives/2009/308_design-patterns-facade.html#comments</comments>
		<pubDate>Mon, 14 Sep 2009 09:25:39 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[facade]]></category>
		<category><![CDATA[外观]]></category>
		<category><![CDATA[设计模式]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=308</guid>
		<description><![CDATA[定义 为子系统中的一组接口提供一个一致的界面，外观（Facade）模式定义了一个高层接口，这个接口使得这一子系统更加容易使用。 &#160; 结构 &#160; 理解 1.&#160;&#160;&#160;&#160;&#160;&#160; Facade提供一个高层接口，将客户的请求代理给适合的子系统（Subsystem）对象，Facade知道子系统的哪些对象来处理请求。 2.&#160;&#160;&#160;&#160;&#160;&#160; Subsystem是一系列类的集合，处理Facade指派的任务。Subsystem不知道Facade的信息。 &#160; 要点 &#160; 1.&#160;&#160;&#160;&#160;&#160;&#160; 一个复杂的系统包括若干个子系统，Facade模式为复杂子系统提供一个简单而统一的接口。譬如编译系统包括代码扫描、语法分析、代码生成等流程，每一个流程可以成为一个子系统。客户编译代码并不想知道具体的细节流程，Facade模式封装一套标准编译流程，就屏蔽了编译的具体流程， 简化了客户调用。下图可以看出应用Facade场景： 2.&#160;&#160;&#160;&#160;&#160;&#160; 提高子系统的独立性和可移植性。客户程序与抽象类的实现部分之间存在着很大的依赖性。引入Facade将这个子系统与客户以及其他的子系统分离，可以提高子系统的独立性和可移植性。 3.&#160;&#160;&#160;&#160;&#160;&#160; 当你需要构建一个层次结构的子系统时，使用Facade模式定义子系统中每层的入口点。如果子系统之间是相互依赖的，你可以让它们仅通过Facade进行通讯，从而简化了它们之间的依赖关系。 &#160; &#160; 应用 源码以编译系统的例子说明外观模式。 &#160; 源码 #include &#60;iostream&#62; #include &#60;string&#62; using namespace std; &#160; //代码扫描读入 class CCodeScanner { public: &#160;&#160;&#160; void Scan() &#160;&#160;&#160; { &#160;&#160;&#160;&#160;&#160;&#160;&#160; cout &#60;&#60; &#34;scan code&#34; &#60;&#60; endl; &#160;&#160;&#160; } }; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p><b><span style="font-size: 12pt; line-height: 150%; font-family: 宋体;">定义</span></b></p>
<div style="line-height: 150%;"><span style="font-family: 宋体;">为子系统中的一组接口提供一个一致的界面，外观（</span>Facade<span style="font-family: 宋体;">）模式定义了一个高层接口，这个接口使得这一子系统更加容易使用。</span></div>
<div style="line-height: 150%;"><span style="font-family: 宋体;"><span id="more-308"></span></span>&nbsp;</div>
<div style="line-height: 150%;"><b><span style="font-size: 12pt; line-height: 150%; font-family: 宋体;">结构</span></b></div>
<div align="center" style="text-align: center; line-height: 150%;"><img width="355" height="256" class="aligncenter size-full wp-image-309" title="facade" alt="facade" src="http://www.shenmiguo.com/wp-content/uploads/2009/09/facade.jpg" /></div>
<div style="line-height: 150%;">&nbsp;</div>
<div style="line-height: 150%;"><b><span style="font-size: 12pt; line-height: 150%; font-family: 宋体;">理解</span></b></div>
<div style="margin-left: 18pt; text-indent: -18pt; line-height: 150%;"><span>1.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Facade<span style="font-family: 宋体;">提供一个高层接口，将客户的请求代理给适合的子系统（</span>Subsystem<span style="font-family: 宋体;">）对象，</span>Facade<span style="font-family: 宋体;">知道子系统的哪些对象来处理请求。</span></div>
<div style="margin-left: 18pt; text-indent: -18pt; line-height: 150%;"><span>2.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Subsystem<span style="font-family: 宋体;">是一系列类的集合，处理</span>Facade<span style="font-family: 宋体;">指派的任务。</span>Subsystem<span style="font-family: 宋体;">不知道</span>Facade<span style="font-family: 宋体;">的信息。</span></div>
<div style="line-height: 150%;">&nbsp;</div>
<div style="line-height: 150%;"><b><span style="font-size: 12pt; line-height: 150%; font-family: 宋体;">要点</span></b></div>
<div style="margin-left: 18pt; text-indent: -18pt; line-height: 150%;">&nbsp;</div>
<div style="margin-left: 18pt; text-indent: -18pt; line-height: 150%;"><span>1.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family: 宋体;">一个复杂的系统包括若干个子系统，</span><span style="color: red;">Facade</span><span style="font-family: 宋体; color: red;">模式为复杂子系统提供一个简单而统一的接口</span><span style="font-family: 宋体;">。譬如编译系统包括代码扫描、语法分析、代码生成等流程，每一个流程可以成为一个子系统。客户编译代码并不想知道具体的细节流程，</span>Facade<span style="font-family: 宋体;">模式封装一套标准编译流程，就屏蔽了编译的具体流程，</span> <span style="font-family: 宋体;">简化了客户调用。下图可以看出应用</span>Facade<span style="font-family: 宋体;">场景：</span></div>
<div align="center" style="margin-left: 18pt; text-align: center; line-height: 150%;"><img width="553" height="196" align="middle" v:shapes="_x0000_i1025" src="http://www.shenmiguo.com/wp-content/uploads/2009/09/facade_subsystem.jpg" alt="" /></div>
<div style="margin-left: 18pt; text-indent: -18pt; line-height: 150%;"><span>2.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family: 宋体; color: red;">提高子系统的独立性和可移植性</span><span style="font-family: 宋体;">。客户程序与抽象类的实现部分之间存在着很大的依赖性。引入</span>Facade<span style="font-family: 宋体;">将这个子系统与客户以及其他的子系统分离，可以提高子系统的独立性和可移植性。</span></div>
<div style="margin-left: 18pt; text-indent: -18pt; line-height: 150%;"><span>3.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family: 宋体;">当你需要构建一个层次结构的子系统时，<span style="color: red;">使用</span></span><span style="color: red;">Facade</span><span style="font-family: 宋体; color: red;">模式定义子系统中每层的入口点</span><span style="font-family: 宋体;">。如果子系统之间是相互依赖的，你可以让它们仅通过</span>Facade<span style="font-family: 宋体;">进行通讯，从而简化了它们之间的依赖关系。</span></div>
<div style="margin-left: 18pt; text-indent: -18pt; line-height: 150%;">&nbsp;</div>
<div style="line-height: 150%;">&nbsp;</div>
<div style="line-height: 150%;"><b><span style="font-size: 12pt; line-height: 150%; font-family: 宋体;">应用</span></b></div>
<div style="line-height: 150%;"><span style="font-family: 宋体;">源码以编译系统的例子说明外观模式。</span></div>
<div style="line-height: 150%;">&nbsp;</div>
<div style="line-height: 150%;"><b><span style="font-size: 12pt; line-height: 150%; font-family: 宋体;">源码</span></b></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">#include</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: rgb(163, 21, 21);">&lt;iostream&gt;</span></span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">#include</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: rgb(163, 21, 21);">&lt;string&gt;</span></span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">using</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: blue;">namespace</span> <span style="color: rgb(1, 0, 1);">std</span>;</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: green;">//</span><span style="font-size: 9pt; font-family: 宋体; color: green;">代码扫描读入</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">class</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: rgb(1, 0, 1);">CCodeScanner</span></span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">{</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">public</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">:</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">void</span> <span style="color: rgb(1, 0, 1);">Scan</span>()</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; {</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">cout</span> &lt;&lt; <span style="color: rgb(163, 21, 21);">&quot;scan code&quot;</span> &lt;&lt; <span style="color: rgb(1, 0, 1);">endl</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; }</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">};</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: green;">//</span><span style="font-size: 9pt; font-family: 宋体; color: green;">语法分析</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">class</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: rgb(1, 0, 1);">CCodeParser</span></span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">{</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">public</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">:</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">void</span> <span style="color: rgb(1, 0, 1);">Parse</span>()</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; {</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">cout</span> &lt;&lt; <span style="color: rgb(163, 21, 21);">&quot;parse code&quot;</span> &lt;&lt; <span style="color: rgb(1, 0, 1);">endl</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; }</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">};</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: green;">//</span><span style="font-size: 9pt; font-family: 宋体; color: green;">代码生成</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">class</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: rgb(1, 0, 1);">CCodeGenerator</span></span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">{</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">public</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">:</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">void</span> <span style="color: rgb(1, 0, 1);">Generate</span>()</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; {</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">cout</span> &lt;&lt; <span style="color: rgb(163, 21, 21);">&quot;generate code&quot;</span> &lt;&lt; <span style="color: rgb(1, 0, 1);">endl</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; }</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">};</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: green;">//Facade</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">class</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: rgb(1, 0, 1);">CCompiler</span></span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">{</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">public</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">:</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: green;">//</span></span><span style="font-size: 9pt; font-family: 宋体; color: green;">更高层的统一接口</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">void</span> <span style="color: rgb(1, 0, 1);">Compile</span>()</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; {</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">cout</span> &lt;&lt; <span style="color: rgb(163, 21, 21);">&quot;compile program&#8230;&quot;</span> &lt;&lt; <span style="color: rgb(1, 0, 1);">endl</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">CCodeScanner</span> <span style="color: rgb(1, 0, 1);">scanner</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">scanner</span>.<span style="color: rgb(1, 0, 1);">Scan</span>();</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">CCodeParser</span> <span style="color: rgb(1, 0, 1);">parser</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">parser</span>.<span style="color: rgb(1, 0, 1);">Parse</span>();</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">CCodeGenerator</span> <span style="color: rgb(1, 0, 1);">generator</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">generator</span>.<span style="color: rgb(1, 0, 1);">Generate</span>();</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; }</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">};</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;; color: blue;">int</span><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;"> <span style="color: rgb(1, 0, 1);">main</span>()</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">{</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">CCompiler</span> <span style="color: rgb(1, 0, 1);">compiler</span>;</span></div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: rgb(1, 0, 1);">compiler</span>.<span style="color: rgb(1, 0, 1);">Compile</span>();</span></div>
<div align="left">&nbsp;</div>
<div align="left"><span style="font-size: 9pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> 0;</span></div>
<div style="line-height: 150%;"><span style="font-size: 9pt; line-height: 150%; font-family: &quot;Courier New&quot;;">}</span></div>
<div style="line-height: 150%;">&nbsp;</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2009/308_design-patterns-facade.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

