﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-HUUYUU</title><link>http://www.cppblog.com/HUUYUU/</link><description /><language>zh-cn</language><lastBuildDate>Mon, 13 Apr 2026 09:40:25 GMT</lastBuildDate><pubDate>Mon, 13 Apr 2026 09:40:25 GMT</pubDate><ttl>60</ttl><item><title>Freetype学习笔记</title><link>http://www.cppblog.com/HUUYUU/archive/2008/07/10/55839.html</link><dc:creator>HUYU</dc:creator><author>HUYU</author><pubDate>Thu, 10 Jul 2008 14:22:00 GMT</pubDate><guid>http://www.cppblog.com/HUUYUU/archive/2008/07/10/55839.html</guid><wfw:comment>http://www.cppblog.com/HUUYUU/comments/55839.html</wfw:comment><comments>http://www.cppblog.com/HUUYUU/archive/2008/07/10/55839.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/HUUYUU/comments/commentRss/55839.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/HUUYUU/services/trackbacks/55839.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 转载时请注明出处和作者联系方式：http://blog.csdn.net/absurd作者联系方式：Li XianJing &lt;xianjimli at hotmail dot com&gt;更新时间：2006-12-19&nbsp;GTK+(基于DirectFB)的字体绘制是通过pango+freetype+fontconfig三者协作来完成的，其中，fontconfig负责...&nbsp;&nbsp;<a href='http://www.cppblog.com/HUUYUU/archive/2008/07/10/55839.html'>阅读全文</a><img src ="http://www.cppblog.com/HUUYUU/aggbug/55839.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/HUUYUU/" target="_blank">HUYU</a> 2008-07-10 22:22 <a href="http://www.cppblog.com/HUUYUU/archive/2008/07/10/55839.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>写operator new和operator delete时要遵循常规</title><link>http://www.cppblog.com/HUUYUU/archive/2008/01/22/41608.html</link><dc:creator>HUYU</dc:creator><author>HUYU</author><pubDate>Tue, 22 Jan 2008 01:42:00 GMT</pubDate><guid>http://www.cppblog.com/HUUYUU/archive/2008/01/22/41608.html</guid><wfw:comment>http://www.cppblog.com/HUUYUU/comments/41608.html</wfw:comment><comments>http://www.cppblog.com/HUUYUU/archive/2008/01/22/41608.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/HUUYUU/comments/commentRss/41608.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/HUUYUU/services/trackbacks/41608.html</trackback:ping><description><![CDATA[<div class=postText>自己重写operator new时，很重要的一点是函数提供的行为要和系统缺省的operator new一致。实际做起来也就是：要有正确的返回值；可用内存不够时要调用出错处理函数；处理好0字节内存请求的情况。此外，还要避免不小心隐藏了标准形式的new。
<p>非类成员形式的operator new的伪代码：
<p>void * operator new(size_t size)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // operator new还可能有其它参数<br>{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<p>&nbsp; if (size == 0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 处理0字节请求时，<br>&nbsp; { </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; size = 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 把它当作1个字节请求来处理</p>
<p>&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; while (1)</p>
<p>{<br>&nbsp;&nbsp;&nbsp; 分配size字节内存;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (分配成功)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (指向内存的指针);</p>
<p>&nbsp;&nbsp;&nbsp; // 分配不成功，找出当前出错处理函数<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new_handler globalhandler = set_new_handler(0);<br>&nbsp;&nbsp;&nbsp;&nbsp; set_new_handler(globalhandler);
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (globalhandler) (*globalhandler)();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else throw std::bad_alloc();<br>&nbsp; }<br>}
<p>&nbsp;
<p>为特定类写的new往往没有考虑该类被继承的情况，使用sizeof(父类)获得大小，但是如果发生子类调用父类的new时，往往
<p>会出错，子类的size往往大于父类的size。最好父类的new应该这么写：
<p>void * base::operator new(size_t size)<br>{<br>&nbsp; if (size != sizeof(base))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // <font color=#ff0000>如果数量&#8220;错误&#8221;，让标准operator new，精华部分。</font><br>&nbsp;&nbsp;&nbsp; return ::operator new(size);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 去处理这个请求<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //
<p>&nbsp; ...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 否则处理这个请求<br>}
<p>&nbsp;
<p>对于operator delete(以及它的伙伴operator delete[])，情况更简单。所要记住的只是，c++保证删除空指针永远是安全的，所以你要充分地应用这一保证。</p>
<p>下面是非类成员形式的operator delete的伪代码：<br>void operator delete(void *rawmemory)<br>{<br>&nbsp; if (rawmemory == 0) return;&nbsp;&nbsp; //如果指针为空，返回<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // </p>
<p>&nbsp; 释放rawmemory指向的内存;
<p>&nbsp; return;<br>}
<p>&nbsp;
<p>这个函数的类成员版本也简单，只是还必须检查被删除的对象的大小。假设类的operator new将&#8220;错误&#8221;大小的分配请求转给::operator new，那么也必须将&#8220;错误&#8221;大小的删除请求转给::operator delete：
<p>void base::operator delete(void *rawmemory, size_t size)<br>{<br>&nbsp; if (rawmemory == 0) return;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 检查空指针
<p>&nbsp; if (size != sizeof(base))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 如果size"错误"，</p>
<p>{&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; ::operator delete(rawmemory);&nbsp; // 让标准operator来处理请求<br>&nbsp;&nbsp;&nbsp; return;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; }</p>
<p>&nbsp; 释放指向rawmemory的内存;
<p>&nbsp; return;<br>}
<p>有关operator new和operator delete(以及他们的数组形式)的规定不是那么麻烦，重要的是必须遵守它。只要内存分配程序支持new-handler函数并正确地处理了零内存请求，就差不多了；如果内存释放程序又处理了空指针，那就没其他什么要做的了。至于在类成员版本的函数里增加继承支持，那将很快就可以完成。</p>
</div>
<img src ="http://www.cppblog.com/HUUYUU/aggbug/41608.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/HUUYUU/" target="_blank">HUYU</a> 2008-01-22 09:42 <a href="http://www.cppblog.com/HUUYUU/archive/2008/01/22/41608.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> 堆和栈的区别</title><link>http://www.cppblog.com/HUUYUU/archive/2008/01/10/38435.html</link><dc:creator>HUYU</dc:creator><author>HUYU</author><pubDate>Thu, 10 Jan 2008 05:22:00 GMT</pubDate><guid>http://www.cppblog.com/HUUYUU/archive/2008/01/10/38435.html</guid><wfw:comment>http://www.cppblog.com/HUUYUU/comments/38435.html</wfw:comment><comments>http://www.cppblog.com/HUUYUU/archive/2008/01/10/38435.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/HUUYUU/comments/commentRss/38435.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/HUUYUU/services/trackbacks/38435.html</trackback:ping><description><![CDATA[<p><font size=1><font color=#0000ff><strong>一、预备知识—程序的内存分配<br></strong>&nbsp;&nbsp;&nbsp; 一个由c/C++编译的程序占用的内存分为以下几个部分<br>&nbsp;&nbsp;&nbsp; 1、栈区（stack）— 由编译器自动分配释放 ，存放函数的参数值，局部变量的值等。其操作方式类似于数据结构中的栈。<br>&nbsp;&nbsp;&nbsp; 2、堆区（heap） — 一般由程序员分配释放， 若程序员不释放，程序结束时可能由OS回收 。注意它与数据结构中的堆是两回事，分配方式倒是类似于链表，呵呵。<br>&nbsp;&nbsp;&nbsp; 3、全局区（静态区）（static）—，全局变量和静态变量的存储是放在一块的，初始化的全局变量和静态变量在一块区域， 未初始化的全局变量和未初始化的静态变量在相邻的另一块区域。 - 程序结束后有系统释放<br>&nbsp;&nbsp;&nbsp; 4、文字常量区—常量字符串就是放在这里的。 程序结束后由系统释放<br>&nbsp;&nbsp;&nbsp; 5、程序代码区—存放函数体的二进制代码。</font></font></p>
<p><font size=1><br><font color=#0000ff><strong>例子程序<br></strong>这是一个前辈写的，非常详细<br>//main.cpp<br>int a = 0; 全局初始化区<br>char *p1; 全局未初始化区<br>main()<br>{<br>int b; 栈<br>char s[] = "abc"; 栈<br>char *p2; 栈<br>char *p3 = "123456"; 123456\0在常量区，p3在栈上。<br>static int c =0； 全局（静态）初始化区<br>p1 = (char *)malloc(10);<br>p2 = (char *)malloc(20);<br>分配得来得10和20字节的区域就在堆区。<br>strcpy(p1, "123456"); 123456\0放在常量区，编译器可能会将它与p3所指向的"123456"优化成一个地方。<br>}<br><br><br><strong><font size=3>二、堆和栈的理论知识</font></strong><br></font><strong><br><font color=#0000ff>2.1申请方式<br></font></strong><font color=#0000ff>stack:<br>由系统自动分配。 例如，声明在函数中一个局部变量 int b; 系统自动在栈中为b开辟空间<br>heap:<br>需要程序员自己申请，并指明大小，在c中malloc函数<br>如p1 = (char *)malloc(10);<br>在C++中用new运算符<br>如p2 = (char *)malloc(10);<br>但是注意p1、p2本身是在栈中的。<br><br><strong>2.2申请后系统的响应</strong><br>栈：只要栈的剩余空间大于所申请空间，系统将为程序提供内存，否则将报异常提示栈溢出。<br>堆：首先应该知道操作系统有一个记录空闲内存地址的链表，当系统收到程序的申请时，<br>会遍历该链表，寻找第一个空间大于所申请空间的堆结点，然后将该结点从空闲结点链表中删除，并将该结点的空间分配给程序，另外，对于大多数系统，会在这块内存空间中的首地址处记录本次分配的大小，这样，代码中的delete语句才能正确的释放本内存空间。另外，由于找到的堆结点的大小不一定正好等于申请的大小，系统会自动的将多余的那部分重新放入空闲链表中。<br><br><strong>2.3申请大小的限制</strong><br>栈：在Windows下,栈是向低地址扩展的数据结构，是一块连续的内存的区域。这句话的意思是栈顶的地址和栈的最大容量是系统预先规定好的，在WINDOWS下，栈的大小是2M（也有的说是1M，总之是一个编译时就确定的常数），如果申请的空间超过栈的剩余空间时，将提示overflow。因此，能从栈获得的空间较小。<br>堆：堆是向高地址扩展的数据结构，是不连续的内存区域。这是由于系统是用链表来存储的空闲内存地址的，自然是不连续的，而链表的遍历方向是由低地址向高地址。堆的大小受限于计算机系统中有效的虚拟内存。由此可见，堆获得的空间比较灵活，也比较大。<br><br><br><strong>2.4申请效率的比较</strong><br>栈由系统自动分配，速度较快。但程序员是无法控制的。<br>堆是由new分配的内存，一般速度比较慢，而且容易产生内存碎片,不过用起来最方便.<br>另外，在WINDOWS下，最好的方式是用VirtualAlloc分配内存，他不是在堆，也不是在栈是直接在进程的地址空间中保留一快内存，虽然用起来最不方便。但是速度快，也最灵活。<br><br><strong>2.5堆和栈中的存储内容</strong><br>栈： 在函数调用时，第一个进栈的是主函数中后的下一条指令（函数调用语句的下一条可执行语句）的地址，然后是函数的各个参数，在大多数的C编译器中，参数是由右往左入栈的，然后是函数中的局部变量。注意静态变量是不入栈的。<br>当本次函数调用结束后，局部变量先出栈，然后是参数，最后栈顶指针指向最开始存的地址，也就是主函数中的下一条指令，程序由该点继续运行。<br>堆：一般是在堆的头部用一个字节存放堆的大小。堆中的具体内容有程序员安排。<br><br><strong>2.6存取效率的比较</strong><br>char s1[] = "aaaaaaaaaaaaaaa";<br>char *s2 = "bbbbbbbbbbbbbbbbb";<br>aaaaaaaaaaa是在运行时刻赋值的；<br>而bbbbbbbbbbb是在编译时就确定的；<br>但是，在以后的存取中，在栈上的数组比指针所指向的字符串(例如堆)快。<br>比如：<br>＃i nclude<br>void main()<br>{<br>char a = 1;<br>char c[] = "1234567890";<br>char *p ="1234567890";<br>a = c[1];<br>a = p[1];<br>return;<br>}<br>对应的汇编代码<br>10: a = c[1];<br>00401067 8A 4D F1 mov cl,byte ptr [ebp-0Fh]<br>0040106A 88 4D FC mov byte ptr [ebp-4],cl<br>11: a = p[1];<br>0040106D 8B 55 EC mov edx,dword ptr [ebp-14h]<br>00401070 8A 42 01 mov al,byte ptr [edx+1]<br>00401073 88 45 FC mov byte ptr [ebp-4],al<br>第一种在读取时直接就把字符串中的元素读到寄存器cl中，而第二种则要先把指针值读到edx中，在根据edx读取字符，显然慢了。<br><br><strong>2.7小结</strong><br>堆和栈的区别可以用如下的比喻来看出：<br>使用栈就象我们去饭馆里吃饭，只管点菜（发出申请）、付钱、和吃（使用），吃饱了就走，不必理会切菜、洗菜等准备工作和洗碗、刷锅等扫尾工作，他的好处是快捷，但是自由度小。<br>使用堆就象是自己动手做喜欢吃的菜肴，比较麻烦，但是比较符合自己的口味，而且自由度大。<br><br><br><br><font size=3><strong>windows进程中的内存结构</strong></font><br><br><br>在阅读本文之前，如果你连</font><a onclick="tagshow(event, '%B6%D1%D5%BB');return false;" href="javascript:;"><u><strong><font color=#800080>堆栈</font></strong></u></a><font color=#0000ff>是什么多不知道的话，请先阅读文章后面的</font><a onclick="tagshow(event, '%BB%F9%B4%A1%D6%AA%CA%B6');return false;" href="javascript:;"><u><strong><font color=#800080>基础知识</font></strong></u></a><font color=#0000ff>。<br><br>接触过</font><a onclick="tagshow(event, '%B1%E0%B3%CC');return false;" href="javascript:;"><u><strong><font color=#800080>编程</font></strong></u></a><font color=#0000ff>的人都知道，高级语言都能通过变量名来访问内存中的数据。那么这些变量在内存中是如何存放的呢？程序又是如何使用这些变量的呢？下面就会对此进行深入的讨论。下文中的C语言代码如没有特别声明，默认都使用VC编译的release版。<br><br>首先，来了解一下 C 语言的变量是如何在内存分部的。C 语言有全局变量(Global)、本地变量(Local)，静态变量(Static)、寄存器变量(Regeister)。每种变量都有不同的分配方式。先来看下面这段代码：<br><br>＃i nclude &lt;stdio.h&gt;<br><br>int g1=0, g2=0, g3=0;<br><br>int main()<br>{<br>static int s1=0, s2=0, s3=0;<br>int v1=0, v2=0, v3=0;<br><br>//打印出各个变量的内存地址<br><br>printf("0x%08x\n",&amp;v1); //打印各本地变量的内存地址<br>printf("0x%08x\n",&amp;v2);<br>printf("0x%08x\n\n",&amp;v3);<br>printf("0x%08x\n",&amp;g1); //打印各全局变量的内存地址<br>printf("0x%08x\n",&amp;g2);<br>printf("0x%08x\n\n",&amp;g3);<br>printf("0x%08x\n",&amp;s1); //打印各静态变量的内存地址<br>printf("0x%08x\n",&amp;s2);<br>printf("0x%08x\n\n",&amp;s3);<br>return 0;<br>}<br><br>编译后的执行结果是：<br><br>0x0012ff78<br>0x0012ff7c<br>0x0012ff80<br><br>0x004068d0<br>0x004068d4<br>0x004068d8<br><br>0x004068dc<br>0x004068e0<br>0x004068e4<br><br>输出的结果就是变量的内存地址。其中v1,v2,v3是本地变量，g1,g2,g3是全局变量，s1,s2,s3是静态变量。你可以看到这些变量在内存是连续分布的，但是本地变量和全局变量分配的内存地址差了十万八千里，而全局变量和静态变量分配的内存是连续的。这是因为本地变量和全局/静态变量是分配在不同类型的内存区域中的结果。对于一个进程的内存空间而言，可以在逻辑上分成3个部份：代码区，静态数据区和动态数据区。动态数据区一般就是&#8220;堆栈&#8221;。&#8220;栈(stack)&#8221;和&#8220;堆(heap)&#8221;是两种不同的动态数据区，栈是一种线性结构，堆是一种链式结构。进程的每个线程都有私有的&#8220;栈&#8221;，所以每个线程虽然代码一样，但本地变量的数据都是互不干扰。一个堆栈可以通过&#8220;基地址&#8221;和&#8220;栈顶&#8221;地址来描述。全局变量和静态变量分配在静态数据区，本地变量分配在动态数据区，即堆栈中。程序通过堆栈的基地址和偏移量来访问本地变量。<br><br><br>├———————┤低端内存区域<br>│ &#8230;&#8230; │<br>├———————┤<br>│ 动态数据区 │<br>├———————┤<br>│ &#8230;&#8230; │<br>├———————┤<br>│ 代码区 │<br>├———————┤<br>│ 静态数据区 │<br>├———————┤<br>│ &#8230;&#8230; │<br>├———————┤高端内存区域<br><br><br>堆栈是一个先进后出的数据结构，栈顶地址总是小于等于栈的基地址。我们可以先了解一下函数调用的过程，以便对堆栈在程序中的作用有更深入的了解。不同的语言有不同的函数调用规定，这些因素有参数的压入规则和堆栈的平衡。windows API的调用规则和ANSI C的函数调用规则是不一样的，前者由被调函数调整堆栈，后者由调用者调整堆栈。两者通过&#8220;__stdcall&#8221;和&#8220;__cdecl&#8221;前缀区分。先看下面这段代码：<br><br>＃i nclude &lt;stdio.h&gt;<br><br>void __stdcall func(int param1,int param2,int param3)<br>{<br>int var1=param1;<br>int var2=param2;<br>int var3=param3;<br>printf("0x%08x\n",?m1); //打印出各个变量的内存地址<br>printf("0x%08x\n",?m2);<br>printf("0x%08x\n\n",?m3);<br>printf("0x%08x\n",&amp;var1);<br>printf("0x%08x\n",&amp;var2);<br>printf("0x%08x\n\n",&amp;var3);<br>return;<br>}<br><br>int main()<br>{<br>func(1,2,3);<br>return 0;<br>}<br><br>编译后的执行结果是：<br><br>0x0012ff78<br>0x0012ff7c<br>0x0012ff80<br><br>0x0012ff68<br>0x0012ff6c<br>0x0012ff70<br><br><br>├———————┤&lt;—函数执行时的栈顶（ESP）、低端内存区域<br>│ &#8230;&#8230; │<br>├———————┤<br>│ var 1 │<br>├———————┤<br>│ var 2 │<br>├———————┤<br>│ var 3 │<br>├———————┤<br>│ RET │<br>├———————┤&lt;—&#8220;__cdecl&#8221;函数返回后的栈顶（ESP）<br>│ parameter 1 │<br>├———————┤<br>│ parameter 2 │<br>├———————┤<br>│ parameter 3 │<br>├———————┤&lt;—&#8220;__stdcall&#8221;函数返回后的栈顶（ESP）<br>│ &#8230;&#8230; │<br>├———————┤&lt;—栈底（基地址 EBP）、高端内存区域<br><br><br>上图就是函数调用过程中堆栈的样子了。首先，三个参数以从又到左的次序压入堆栈，先压&#8220;param3&#8221;，再压&#8220;param2&#8221;，最后压入&#8220;param1&#8221;；然后压入函数的返回地址(RET)，接着跳转到函数地址接着执行（这里要补充一点，介绍UNIX下的缓冲溢出原理的文章中都提到在压入RET后，继续压入当前EBP，然后用当前ESP代替EBP。然而，有一篇介绍windows下函数调用的文章中说，在windows下的函数调用也有这一步骤，但根据我的实际调试，并未发现这一步，这还可以从param3和var1之间只有4字节的间隙这点看出来）；第三步，将栈顶(ESP)减去一个数，为本地变量分配内存空间，上例中是减去12字节(ESP=ESP-3*4，每个int变量占用4个字节)；接着就初始化本地变量的内存空间。由于&#8220;__stdcall&#8221;调用由被调函数调整堆栈，所以在函数返回前要恢复堆栈，先回收本地变量占用的内存(ESP=ESP+3*4)，然后取出返回地址，填入EIP寄存器，回收先前压入参数占用的内存(ESP=ESP+3*4)，继续执行调用者的代码。参见下列汇编代码：<br><br>;--------------func 函数的汇编代码-------------------<br><br>:00401000 83EC0C sub esp, 0000000C //创建本地变量的内存空间<br>:00401003 8B442410 mov eax, dword ptr [esp+10]<br>:00401007 8B4C2414 mov ecx, dword ptr [esp+14]<br>:0040100B 8B542418 mov edx, dword ptr [esp+18]<br>:0040100F 89442400 mov dword ptr [esp], eax<br>:00401013 8D442410 lea eax, dword ptr [esp+10]<br>:00401017 894C2404 mov dword ptr [esp+04], ecx<br><br>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;（省略若干代码）<br><br>:00401075 83C43C add esp, 0000003C ;恢复堆栈，回收本地变量的内存空间<br>:00401078 C3 ret 000C ;函数返回，恢复参数占用的内存空间<br>;如果是&#8220;__cdecl&#8221;的话，这里是&#8220;ret&#8221;，堆栈将由调用者恢复<br><br>;-------------------函数结束-------------------------<br><br><br>;--------------主程序调用func函数的代码--------------<br><br>:00401080 6A03 push 00000003 //压入参数param3<br>:00401082 6A02 push 00000002 //压入参数param2<br>:00401084 6A01 push 00000001 //压入参数param1<br>:00401086 E875FFFFFF call 00401000 //调用func函数<br>;如果是&#8220;__cdecl&#8221;的话，将在这里恢复堆栈，&#8220;add esp, 0000000C&#8221;<br><br>聪明的读者看到这里，差不多就明白缓冲溢出的原理了。先来看下面的代码：<br><br>＃i nclude &lt;stdio.h&gt;<br>＃i nclude &lt;string.h&gt;<br><br>void __stdcall func()<br>{<br>char lpBuff[8]="\0";<br>strcat(lpBuff,"AAAAAAAAAAA");<br>return;<br>}<br><br>int main()<br>{<br>func();<br>return 0;<br>}<br><br>编译后执行一下回怎么样？哈，&#8220;"0x00414141"指令引用的"0x00000000"内存。该内存不能为"read"。&#8221;，&#8220;非法操作&#8221;喽！"41"就是"A"的16进制的ASCII码了，那明显就是strcat这句出的问题了。"lpBuff"的大小只有8字节，算进结尾的\0，那strcat最多只能写入7个"A"，但程序实际写入了11个"A"外加1个\0。再来看看上面那幅图，多出来的4个字节正好覆盖了RET的所在的内存空间，导致函数返回到一个错误的内存地址，执行了错误的指令。如果能精心构造这个字符串，使它分成三部分，前一部份仅仅是填充的无意义数据以达到溢出的目的，接着是一个覆盖RET的数据，紧接着是一段shellcode，那只要着个RET地址能指向这段shellcode的第一个指令，那函数返回时就能执行shellcode了。但是软件的不同版本和不同的运行环境都可能影响这段shellcode在内存中的位置，那么要构造这个RET是十分困难的。一般都在RET和shellcode之间填充大量的NOP指令，使得exploit有更强的通用性。<br><br><br>├———————┤&lt;—低端内存区域<br>│ &#8230;&#8230; │<br>├———————┤&lt;—由exploit填入数据的开始<br>│ │<br>│ buffer │&lt;—填入无用的数据<br>│ │<br>├———————┤<br>│ RET │&lt;—指向shellcode，或NOP指令的范围<br>├———————┤<br>│ NOP │<br>│ &#8230;&#8230; │&lt;—填入的NOP指令，是RET可指向的范围<br>│ NOP │<br>├———————┤<br>│ │<br>│ shellcode │<br>│ │<br>├———————┤&lt;—由exploit填入数据的结束<br>│ &#8230;&#8230; │<br>├———————┤&lt;—高端内存区域<br><br><br>windows下的动态数据除了可存放在栈中，还可以存放在堆中。了解C++的朋友都知道，C++可以使用new关键字来动态分配内存。来看下面的C++代码：<br><br>＃i nclude &lt;stdio.h&gt;<br>＃i nclude &lt;iostream.h&gt;<br>＃i nclude &lt;windows.h&gt;<br><br>void func()<br>{<br>char *buffer=new char[128];<br>char bufflocal[128];<br>static char buffstatic[128];<br>printf("0x%08x\n",buffer); //打印堆中变量的内存地址<br>printf("0x%08x\n",bufflocal); //打印本地变量的内存地址<br>printf("0x%08x\n",buffstatic); //打印静态变量的内存地址<br>}<br><br>void main()<br>{<br>func();<br>return;<br>}<br><br>程序执行结果为：<br><br>0x004107d0<br>0x0012ff04<br>0x004068c0<br><br>可以发现用new关键字分配的内存即不在栈中，也不在静态数据区。VC编译器是通过windows下的&#8220;堆(heap)&#8221;来实现new关键字的内存动态分配。在讲&#8220;堆&#8221;之前，先来了解一下和&#8220;堆&#8221;有关的几个API函数：<br><br>HeapAlloc 在堆中申请内存空间<br>HeapCreate 创建一个新的堆对象<br>HeapDestroy 销毁一个堆对象<br>HeapFree 释放申请的内存<br>HeapWalk 枚举堆对象的所有内存块<br>GetProcessHeap 取得进程的默认堆对象<br>GetProcessHeaps 取得进程所有的堆对象<br>LocalAlloc<br>GlobalAlloc<br><br>当进程初始化时，系统会自动为进程创建一个默认堆，这个堆默认所占内存的大小为1M。堆对象由系统进行管理，它在内存中以链式结构存在。通过下面的代码可以通过堆动态申请内存空间：<br><br>HANDLE hHeap=GetProcessHeap();<br>char *buff=HeapAlloc(hHeap,0,8);<br><br>其中hHeap是堆对象的句柄，buff是指向申请的内存空间的地址。那这个hHeap究竟是什么呢？它的值有什么意义吗？看看下面这段代码吧：<br><br>#pragma comment(linker,"/entry:main") //定义程序的入口<br>＃i nclude &lt;windows.h&gt;<br><br>_CRTIMP int (__cdecl *printf)(const char *, ...); //定义STL函数printf<br>/*---------------------------------------------------------------------------<br>写到这里，我们顺便来复习一下前面所讲的知识：<br>(*注)printf函数是C语言的标准函数库中函数，VC的标准函数库由msvcrt.dll模块实现。<br>由函数定义可见，printf的参数个数是可变的，函数内部无法预先知道调用者压入的参数个数，函数只能通过分析第一个参数字符串的格式来获得压入参数的信息，由于这里参数的个数是动态的，所以必须由调用者来平衡堆栈，这里便使用了__cdecl调用规则。BTW，Windows系统的API函数基本上是__stdcall调用形式，只有一个API例外，那就是wsprintf，它使用__cdecl调用规则，同printf函数一样，这是由于它的参数个数是可变的缘故。<br>---------------------------------------------------------------------------*/<br>void main()<br>{<br>HANDLE hHeap=GetProcessHeap();<br>char *buff=HeapAlloc(hHeap,0,0x10);<br>char *buff2=HeapAlloc(hHeap,0,0x10);<br>HMODULE hMsvcrt=LoadLibrary("msvcrt.dll");<br>printf=(void *)GetProcAddress(hMsvcrt,"printf");<br>printf("0x%08x\n",hHeap);<br>printf("0x%08x\n",buff);<br>printf("0x%08x\n\n",buff2);<br>}<br><br>执行结果为：<br><br>0x00130000<br>0x00133100<br>0x00133118<br><br>hHeap的值怎么和那个buff的值那么接近呢？其实hHeap这个句柄就是指向HEAP首部的地址。在进程的用户区存着一个叫PEB(进程环境块)的结构，这个结构中存放着一些有关进程的重要信息，其中在PEB首地址偏移0x18处存放的ProcessHeap就是进程默认堆的地址，而偏移0x90处存放了指向进程所有堆的地址列表的指针。windows有很多API都使用进程的默认堆来存放动态数据，如windows 2000下的所有ANSI版本的函数都是在默认堆中申请内存来转换ANSI字符串到Unicode字符串的。对一个堆的访问是顺序进行的，同一时刻只能有一个线程访问堆中的数据，当多个线程同时有访问要求时，只能排队等待，这样便造成程序执行效率下降。<br><br>最后来说说内存中的数据对齐。所位数据对齐，是指数据所在的内存地址必须是该数据长度的整数倍，DWORD数据的内存起始地址能被4除尽，WORD数据的内存起始地址能被2除尽，x86 CPU能直接访问对齐的数据，当他试图访问一个未对齐的数据时，会在内部进行一系列的调整，这些调整对于程序来说是透明的，但是会降低运行速度，所以编译器在编译程序时会尽量保证数据对齐。同样一段代码，我们来看看用VC、Dev-C++和lcc三个不同编译器编译出来的程序的执行结果：<br><br>＃i nclude &lt;stdio.h&gt;<br><br>int main()<br>{<br>int a;<br>char b;<br>int c;<br>printf("0x%08x\n",&amp;a);<br>printf("0x%08x\n",&amp;b);<br>printf("0x%08x\n",&amp;c);<br>return 0;<br>}<br><br>这是用VC编译后的执行结果：<br>0x0012ff7c<br>0x0012ff7b<br>0x0012ff80<br>变量在内存中的顺序：b(1字节)-a(4字节)-c(4字节)。<br><br>这是用Dev-C++编译后的执行结果：<br>0x0022ff7c<br>0x0022ff7b<br>0x0022ff74<br>变量在内存中的顺序：c(4字节)-中间相隔3字节-b(占1字节)-a(4字节)。<br><br>这是用lcc编译后的执行结果：<br>0x0012ff6c<br>0x0012ff6b<br>0x0012ff64<br>变量在内存中的顺序：同上。<br><br>三个编译器都做到了数据对齐，但是后两个编译器显然没VC&#8220;聪明&#8221;，让一个char占了4字节，浪费内存哦。<br><br><br><strong><font size=3>基础知识：</font></strong><br>堆栈是一种简单的数据结构，是一种只允许在其一端进行插入或删除的线性表。允许插入或删除操作的一端称为栈顶，另一端称为栈底，对堆栈的插入和删除操作被称为入栈和出栈。有一组CPU指令可以实现对进程的内存实现堆栈访问。其中，POP指令实现出栈操作，PUSH指令实现入栈操作。CPU的ESP寄存器存放当前线程的栈顶指针，EBP寄存器中保存当前线程的栈底指针。CPU的EIP寄存器存放下一个CPU指令存放的内存地址，当CPU执行完当前的指令后，从EIP寄存器中读取下一条指令的内存地址，然后继续执行。 </font></font></p>
<p>&nbsp;&lt;br&gt;</p>
<p>堆（Heap）栈（Stack） </p>
<p><strong>1、内存分配方面：</strong> </p>
<p>&nbsp;&nbsp;&nbsp; 堆：一般由<strong>程序员</strong>分配释放， 若程序员不释放，程序结束时可能由OS回收 。注意它与数据结构中的堆是两回事，分配方式是类似于链表。可能用到的关键字如下：<strong>new</strong>、<strong>malloc</strong>、<strong>delete</strong>、<strong>free</strong>等等。 </p>
<p>&nbsp;&nbsp;&nbsp; 栈：由<strong>编译器</strong>(Compiler)自动分配释放，存放<strong>函数的参数值</strong>，<strong>局部变量</strong>的值等。其操作方式类似于数据结构中的栈。 </p>
<p><strong>2、申请方式方面：</strong> </p>
<p>&nbsp;&nbsp;&nbsp; 堆：需要程序员自己申请，并指明大小。在c中malloc函数如p1 = (char *)malloc(10)；在C++中用new运算符，但是注意p1、p2本身是在栈中的。因为他们还是可以认为是局部变量。 </p>
<p>&nbsp;&nbsp;&nbsp; 栈：由系统自动分配。 例如，声明在函数中一个局部变量 int b；系统自动在栈中为b开辟空间。 </p>
<p><strong>3、系统响应方面：</strong> </p>
<p><strong>&nbsp;&nbsp;&nbsp; </strong>堆：操作系统有一个记录空闲内存地址的链表，当系统收到程序的申请时，会遍历该链表，寻找第一个空间大于所申请空间的堆结点，然后将该结点从空闲结点链表中删除，并将该结点的空间分配给程序，另外，对于大多数系统，会在这块内存空间中的首地址处记录本次分配的大小，这样代码中的delete语句才能正确的释放本内存空间。另外由于找到的堆结点的大小不一定正好等于申请的大小，系统会自动的将多余的那部分重新放入空闲链表中。 </p>
<p><strong>&nbsp;&nbsp;&nbsp; </strong>栈：只要栈的剩余空间大于所申请空间，系统将为程序提供内存，否则将报异常提示栈溢出。 </p>
<p><strong>4、大小限制方面：</strong> </p>
<p><strong>&nbsp;&nbsp;&nbsp; </strong>堆：是<strong>向高地址扩展</strong>的数据结构，是<strong>不连续</strong>的内存区域。这是由于系统是用链表来存储的空闲内存地址的，自然是不连续的，而链表的遍历方向是由低地址向高地址。堆的大小受限于计算机系统中<strong>有效的虚拟内存</strong>。由此可见，堆获得的空间比较灵活，也比较大。 </p>
<p><strong>&nbsp;&nbsp;&nbsp; </strong>栈：在Windows下, 栈是<strong>向低地址扩展</strong>的数据结构，是一块<strong>连续</strong>的内存的区域。这句话的意思是栈顶的地址和栈的最大容量是<strong>系统预先规定好</strong>的，在WINDOWS下，栈的大小是固定的（是一个编译时就确定的常数），如果申请的空间超过栈的剩余空间时，将提示overflow。因此，能从栈获得的空间较小。 </p>
<p><strong>5、效率方面：</strong> </p>
<p><strong>&nbsp;&nbsp;&nbsp; </strong>堆：是由new分配的内存，一般速度比较慢，而且<strong>容易产生内存碎片</strong>，不过用起来最<strong>方便</strong>，另外，在WINDOWS下，最好的方式是用VirtualAlloc分配内存，他不是在堆，也不是在栈是直接在进程的地址空间中保留一快内存，虽然用起来最不方便。但是速度快，也最灵活。 </p>
<p><strong>&nbsp;&nbsp;&nbsp; </strong>栈：由系统自动分配，速度较快。但程序员是<strong>无法控制</strong>的。 </p>
<p><strong>6、存放内容方面：</strong> </p>
<p>&nbsp;&nbsp;&nbsp; 堆：一般是在堆的头部用一个字节存放堆的大小。<strong>堆中的具体内容有程序员安排。</strong> </p>
<p>&nbsp;&nbsp;&nbsp; 栈：在函数调用时第一个进栈的是主函数中后的下一条指令（函数调用语句的下一条可执行语句）的<strong>地址</strong>然后是函数的各个参数，在大多数的C编译器中，<strong>参数是由右往左入栈</strong>，然后是函数中的局部变量。 <strong>注意: 静态变量是不入栈的</strong>。当本次函数调用结束后，局部变量先出栈，然后是参数，最后栈顶指针指向最开始存的地址，也就是主函数中的下一条指令，<strong>程序由该点继续运行</strong>。 </p>
<p><strong>7、存取效率方面：</strong> </p>
<p><strong>&nbsp;&nbsp;&nbsp; </strong>堆：char *s1 = "Hellow Word"；是在<strong>编译时</strong>就确定的； </p>
<p>&nbsp;&nbsp;&nbsp; 栈：char s1[] = "Hellow Word"； 是在<strong>运行时</strong>赋值的；用数组比用指针速度要快一些，因为指针在底层汇编中需要用edx寄存器中转一下，而数组在栈上直接读取。</p>
<br>&nbsp;<br><br>
<p id=TBPingURL>Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1925576</p>
<img src ="http://www.cppblog.com/HUUYUU/aggbug/38435.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/HUUYUU/" target="_blank">HUYU</a> 2008-01-10 13:22 <a href="http://www.cppblog.com/HUUYUU/archive/2008/01/10/38435.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Variable Parameters Print Example</title><link>http://www.cppblog.com/HUUYUU/archive/2007/01/19/17792.html</link><dc:creator>HUYU</dc:creator><author>HUYU</author><pubDate>Fri, 19 Jan 2007 09:55:00 GMT</pubDate><guid>http://www.cppblog.com/HUUYUU/archive/2007/01/19/17792.html</guid><wfw:comment>http://www.cppblog.com/HUUYUU/comments/17792.html</wfw:comment><comments>http://www.cppblog.com/HUUYUU/archive/2007/01/19/17792.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/HUUYUU/comments/commentRss/17792.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/HUUYUU/services/trackbacks/17792.html</trackback:ping><description><![CDATA[<p>#include &lt;stdio.h&gt;<br>#include &lt;string.h&gt;<br>#include &lt;stdarg.h&gt;</p>
<p>#include "drm_korea_def.h"</p>
<p>#ifdef __KDRM_FSTRACE</p>
<p>#define LOG_BUFFER_SIZE&nbsp;512<br>#define LOG_LINE_NUM&nbsp;&nbsp;16</p>
<p>#ifdef WIN32<br>#define LOG_FILE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FILE *<br>#define LOG_OPEN(s, m)&nbsp;&nbsp;&nbsp;fopen(s, m)<br>#define LOG_CLOSE(hLog)&nbsp;&nbsp;&nbsp;fclose(hLog)<br>#define LOG_READ (hLog, p, x)&nbsp;&nbsp;fread (p, x, 1, hLog)<br>#define LOG_WRITE(hLog, p, x)&nbsp;fwrite(p, x, 1, hLog)<br>#define LOG_PUTC(hLog, c)&nbsp;&nbsp;fputc(c, hLog)<br>#define LOG_PUTS(hLog, s)&nbsp;&nbsp;fputs(s, hLog)<br>#else<br>#define LOG_FILE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int32_t<br>#define LOG_OPEN(s, m)&nbsp;&nbsp;&nbsp;Fopen((uint8_t *)s, (uint8_t *)m)<br>#define LOG_CLOSE(hLog)&nbsp;&nbsp;&nbsp;Fclose(hLog)<br>#define LOG_READ (hLog, p, x)&nbsp;&nbsp;Fread (hLog,&nbsp; p, x)<br>#define LOG_WRITE(hLog, p, x)&nbsp;Fwrite(hLog, p, x)<br>#define LOG_PUTC(hLog, c)&nbsp;&nbsp;Fputc(hLog, c)<br>#define LOG_PUTS(hLog, s)&nbsp;&nbsp;Fputs(hLog, (uint8_t *)s)<br>#endif</p>
<p>static LOG_FILE fpLogfile;<br>static char logBuffer[LOG_BUFFER_SIZE];</p>
<p>void log_Init(char *logName)<br>{<br>&nbsp;fpLogfile = LOG_OPEN(logName, "w+");</p>
<p>&nbsp;if(fpLogfile &gt; 0)<br>&nbsp;{<br>&nbsp;&nbsp;log_Print("\r\n====&gt; Starting ... :%s %s\r\n", __TIME__, __FILE__);<br>&nbsp;}<br>}</p>
<p>void log_Print(char *logFormat, ...)<br>{<br>&nbsp;if(fpLogfile &gt; 0)<br>&nbsp;{<br>&nbsp;&nbsp;va_list va;<br>&nbsp;&nbsp;int len;</p>
<p>&nbsp;&nbsp;va_start(va, logFormat);<br>&nbsp;&nbsp;len = vsprintf(logBuffer, logFormat, va);<br>&nbsp;&nbsp;va_end(va);</p>
<p>&nbsp;&nbsp;logBuffer[len+1] = 0;</p>
<p>&nbsp;&nbsp;LOG_PUTS(fpLogfile, logBuffer);<br>&nbsp;}<br>}</p>
<p>char Hex2Dec(unsigned char bHex)<br>{<br>&nbsp;bHex &amp;= 0x0F;<br>&nbsp;bHex += bHex&lt;10? '0': 'A' - 10;</p>
<p>&nbsp;return bHex;<br>}</p>
<p>void log_Dump(const unsigned char&nbsp; *pCache, int u32Size, bool bBinary)<br>{<br>&nbsp;int i, stride;<br>&nbsp;unsigned char *p = (unsigned char&nbsp; *)pCache;<br>&nbsp;char cTmp;</p>
<p>&nbsp;if(fpLogfile &lt; 0)<br>&nbsp;&nbsp;return;</p>
<p>&nbsp;if(bBinary)<br>&nbsp;{ <br>&nbsp;&nbsp;for(; p&lt;pCache+u32Size; p+=LOG_BUFFER_SIZE)<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;stride = (p+LOG_BUFFER_SIZE &lt;= pCache+u32Size)? LOG_BUFFER_SIZE: u32Size%LOG_BUFFER_SIZE;<br>&nbsp;&nbsp;&nbsp;LOG_WRITE(fpLogfile, p, stride);<br>&nbsp;&nbsp;}<br>&nbsp;}<br>&nbsp;else<br>&nbsp;{<br>&nbsp;&nbsp;for(; p&lt;pCache+u32Size; p+=LOG_LINE_NUM)<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;stride = (p+LOG_LINE_NUM &lt;= pCache+u32Size)? LOG_LINE_NUM:u32Size%LOG_LINE_NUM;</p>
<p>&nbsp;&nbsp;&nbsp;for(i=0; i&lt;stride; i++)<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;cTmp = Hex2Dec((p[i]&amp;0xF0) &gt;&gt; 4);<br>&nbsp;&nbsp;&nbsp;&nbsp;LOG_PUTC(fpLogfile, cTmp);<br>&nbsp;&nbsp;&nbsp;&nbsp;cTmp = Hex2Dec(p[i]&amp;0x0F);<br>&nbsp;&nbsp;&nbsp;&nbsp;LOG_PUTC(fpLogfile, cTmp);<br>&nbsp;&nbsp;&nbsp;&nbsp;LOG_PUTC(fpLogfile, ' ');<br>&nbsp;&nbsp;&nbsp;&nbsp;if(i== (LOG_LINE_NUM/2 - 1))<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LOG_PUTC(fpLogfile, '-');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LOG_PUTC(fpLogfile, ' ');<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;LOG_PUTC(fpLogfile, '\n');<br>&nbsp;&nbsp;}<br>&nbsp;}<br>}</p>
<p>void log_Terminate(void)<br>{<br>&nbsp;if(fpLogfile &gt; 0)<br>&nbsp;{<br>&nbsp;&nbsp;log_Print("&lt;==== Stopping ... :%s\r\n", __TIME__);<br>&nbsp;&nbsp;LOG_CLOSE(fpLogfile);<br>&nbsp;}<br>}</p>
<p>#endif //__KDRM_FSTRACE</p>
<img src ="http://www.cppblog.com/HUUYUU/aggbug/17792.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/HUUYUU/" target="_blank">HUYU</a> 2007-01-19 17:55 <a href="http://www.cppblog.com/HUUYUU/archive/2007/01/19/17792.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>FreeType2研究 </title><link>http://www.cppblog.com/HUUYUU/archive/2006/11/10/14985.html</link><dc:creator>HUYU</dc:creator><author>HUYU</author><pubDate>Fri, 10 Nov 2006 15:00:00 GMT</pubDate><guid>http://www.cppblog.com/HUUYUU/archive/2006/11/10/14985.html</guid><wfw:comment>http://www.cppblog.com/HUUYUU/comments/14985.html</wfw:comment><comments>http://www.cppblog.com/HUUYUU/archive/2006/11/10/14985.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/HUUYUU/comments/commentRss/14985.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/HUUYUU/services/trackbacks/14985.html</trackback:ping><description><![CDATA[
		<h2>
				<a id="viewpost1_TitleUrl" href="/wlwlxj/archive/2006/11/08/14843.html">
						<font color="#770000">FreeType2研究</font>
				</a>
		</h2>
		<p>最近学习状态不佳，感觉什么都想做却什么也做不下去，浮躁之极。大的库一下子研究不下来，索性找一下小库来看看。<br />游戏里面一般都涉及到文本、压缩、图像、脚本的概念，为了将来有机会研究游戏所以先下手这些小库，不求甚解只求用好。<br /><br />先从字体着手，FreeType字体作为一种字体文件编程开发包，广泛易用在游戏里面。网上汉语资料比较少，只能看它的faq。翻译了部分如下：<br /></p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US">FreeType 2 Library</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US">FAQ</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（当前下载地址：</span>
				<span lang="EN-US">
						<a href="http://sourceforge.net/project/showfiles.php?group_id=3157">
								<font color="#770000">http://sourceforge.net/project/showfiles.php?group_id=3157</font>
						</a>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">版本</span>
				<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /?>
				<st1:chsdate w:st="on" year="1899" month="12" day="30" islunardate="False" isrocdate="False">
						<span lang="EN-US">2.2.1</span>
				</st1:chsdate>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l3 level1 lfo1; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">1、<span style="FONT: 7pt 'Times New Roman'">  </span></span>
				</span>
				<span lang="EN-US">FreeType2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是什么？</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">它是一个为各种应用程序提供通用的字体文件访问的软件包。尤其值得注意的以下特性：</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo2; tab-stops: list 39.0pt">
				<span lang="EN-US" style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings">
						<span style="mso-list: Ignore">l<span style="FONT: 7pt 'Times New Roman'">         </span></span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">提供统一的字体文件访问接口。支持位图和向量格式，包括</span>
				<span lang="EN-US">TrueType</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</span>
				<span lang="EN-US">OpenType</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</span>
				<span lang="EN-US">Typel</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</span>
				<span lang="EN-US">CID</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</span>
				<span lang="EN-US">CFF</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</span>
				<span lang="EN-US">Windows FON/FNT</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</span>
				<span lang="EN-US">X11 PCF</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo2; tab-stops: list 39.0pt">
				<span lang="EN-US" style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings">
						<span style="mso-list: Ignore">l<span style="FONT: 7pt 'Times New Roman'">         </span></span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">提供高效反走样的基于</span>
				<span lang="EN-US">256</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">灰度级的位图字形的生产。</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo2; tab-stops: list 39.0pt">
				<span lang="EN-US" style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings">
						<span style="mso-list: Ignore">l<span style="FONT: 7pt 'Times New Roman'">         </span></span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">模块清晰，每种字体格式对于一个模块。类库的构建可以按照你需要支持的格式进行裁减以减小代码尺寸。（最小的反走样</span>
				<span lang="EN-US">FreeType</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">库</span>
				<span lang="EN-US">&lt;30Kb</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l3 level1 lfo1; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">2、<span style="FONT: 7pt 'Times New Roman'">  </span></span>
				</span>
				<span lang="EN-US">FreeType2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">能做什么？</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt">
				<span lang="EN-US">FT2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">已经易用于许多领域。例如：</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l3 level2 lfo1; tab-stops: list 42.0pt">
				<span lang="EN-US" style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings">
						<span style="mso-list: Ignore">l<span style="FONT: 7pt 'Times New Roman'">         </span></span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图形子系统和文本显示库</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l3 level2 lfo1; tab-stops: list 42.0pt">
				<span lang="EN-US" style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings">
						<span style="mso-list: Ignore">l<span style="FONT: 7pt 'Times New Roman'">         </span></span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文本排版（布局、分页、渲染）</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l3 level2 lfo1; tab-stops: list 42.0pt">
				<span lang="EN-US" style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings">
						<span style="mso-list: Ignore">l<span style="FONT: 7pt 'Times New Roman'">         </span></span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">字体识别和转换工具</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一般来说，该库使得你能轻松的操纵字体文件。</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l3 level1 lfo1; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">3、<span style="FONT: 7pt 'Times New Roman'">  </span></span>
				</span>
				<span lang="EN-US">FreeType2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不能做什么？</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt">
				<span lang="EN-US">FT2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">并不包含大量丰富的高级特性，它只定位于出色的字体服务。也就是说下面的一些特性</span>
				<span lang="EN-US">FT2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类库并不直接提供支持，然而你可以以它为基础在上层进行实现：</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -21pt; mso-list: l4 level1 lfo3; tab-stops: list 39.0pt">
				<span lang="EN-US" style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings">
						<span style="mso-list: Ignore">l<span style="FONT: 7pt 'Times New Roman'">         </span></span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">任意表面的文字渲染</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt">
				<span lang="EN-US">FT2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不是图形库所以它仅支持两种象素格式的文本渲染：</span>
				<span lang="EN-US">1-bit</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的单色位图和</span>
				<span lang="EN-US">8-bit</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的灰度象素。</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果你需要绘制其它格式的表面（例如</span>
				<span lang="EN-US">24-bit RGB</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">象素），你就得选择其它你喜爱的图形库来做。</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt">
				<i style="mso-bidi-font-style: normal">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">注意：为了渲染向量轮廓文本而不是放走样的象素，应用程序可以提供自己的渲染回调以绘制或者直接组合反走样文本到任意目标表面。</span>
						<span lang="EN-US">
								<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?>
								<o:p>
								</o:p>
						</span>
				</i>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -21pt; mso-list: l4 level1 lfo3; tab-stops: list 39.0pt">
				<span lang="EN-US" style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings">
						<span style="mso-list: Ignore">l<span style="FONT: 7pt 'Times New Roman'">         </span></span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文本缓存</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">每次从字体中请求文本图象，</span>
				<span lang="EN-US">FT2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">都要解析字体文件</span>
				<span lang="EN-US">/</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">流相关部分，通过它的字体格式进行解释。对于某些特殊格式可能会很慢包括像</span>
				<span lang="EN-US">TrueType</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（或者</span>
				<span lang="EN-US">Type1</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）这样的向量字体。</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt">
				<i style="mso-bidi-font-style: normal">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">注意：自从</span>
						<st1:chsdate w:st="on" year="1899" month="12" day="30" islunardate="False" isrocdate="False">
								<span lang="EN-US">2.0.1</span>
						</st1:chsdate>
				</i>
				<i style="mso-bidi-font-style: normal">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">版本开始</span>
						<span lang="EN-US">FT2</span>
				</i>
				<i style="mso-bidi-font-style: normal">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">提供了一个</span>
						<span lang="EN-US">beta</span>
				</i>
				<i style="mso-bidi-font-style: normal">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">版本的缓存子系统。当然你还是可以写自己的缓存来满足某种特殊需求。</span>
						<span lang="EN-US">
								<o:p>
								</o:p>
						</span>
				</i>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -21pt; mso-list: l4 level1 lfo3; tab-stops: list 39.0pt">
				<span lang="EN-US" style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings">
						<span style="mso-list: Ignore">l<span style="FONT: 7pt 'Times New Roman'">         </span></span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文本布局</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不支持文本布局操作。高级操作例如文本替换、字距调整、两端调整等都不属于字体服务本身职责。</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l3 level1 lfo1; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">4、<span style="FONT: 7pt 'Times New Roman'">  </span></span>
				</span>
				<span lang="EN-US">FreeType2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可移植性？</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt">
				<span lang="EN-US">FT2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">源码可移植性很好由于以下原因：</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -21pt; mso-list: l4 level1 lfo3; tab-stops: list 39.0pt">
				<span lang="EN-US" style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings">
						<span style="mso-list: Ignore">l<span style="FONT: 7pt 'Times New Roman'">         </span></span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代码书写遵循</span>
				<span lang="EN-US">ANSI C</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">标准</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -21pt; mso-list: l4 level1 lfo3; tab-stops: list 39.0pt">
				<span lang="EN-US" style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings">
						<span style="mso-list: Ignore">l<span style="FONT: 7pt 'Times New Roman'">         </span></span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对于各种编译警告我们都谨慎的避免。当前代码在很多编译器上编译通过且没有产生一条警告。</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -21pt; mso-list: l4 level1 lfo3; tab-stops: list 39.0pt">
				<span lang="EN-US" style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings">
						<span style="mso-list: Ignore">l<span style="FONT: 7pt 'Times New Roman'">         </span></span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">库没有使用任何硬编码，是嵌入式系统开发的一个好的选择。（例如它能够直接在</span>
				<span lang="EN-US">ROM</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中运行）</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">同时，我们尽最大努力确保库的高效、紧凑和友好性。</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l3 level1 lfo1; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">5、<span style="FONT: 7pt 'Times New Roman'">  </span></span>
				</span>
				<span lang="EN-US">FreeType2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与</span>
				<span lang="EN-US">FreeType1.x</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的区别？</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">最大的区别就是：</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -21pt; mso-list: l2 level1 lfo4; tab-stops: list 39.0pt">
				<span lang="EN-US" style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings">
						<span style="mso-list: Ignore">l<span style="FONT: 7pt 'Times New Roman'">         </span></span>
				</span>
				<span lang="EN-US">FT1</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">仅支持</span>
				<span lang="EN-US">TrueType</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">格式，而</span>
				<span lang="EN-US">FT2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">支持很多格式。</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -21pt; mso-list: l2 level1 lfo4; tab-stops: list 39.0pt">
				<span lang="EN-US" style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings">
						<span style="mso-list: Ignore">l<span style="FONT: 7pt 'Times New Roman'">         </span></span>
				</span>
				<span lang="EN-US">FT2 APIs</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">比</span>
				<span lang="EN-US">FT1 APIs</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">简单且强大。</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 39pt; TEXT-INDENT: -21pt; mso-list: l2 level1 lfo4; tab-stops: list 39.0pt">
				<span lang="EN-US" style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings">
						<span style="mso-list: Ignore">l<span style="FONT: 7pt 'Times New Roman'">         </span></span>
				</span>
				<span lang="EN-US">FT1</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">包括</span>
				<span lang="EN-US">OpenType</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文本布局处理扩展，而</span>
				<span lang="EN-US">FT2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中则不包括而是移到独立的工程里面――</span>
				<i style="mso-bidi-font-style: normal">
						<span lang="EN-US">FreeType Layout</span>
				</i>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。（</span>
				<span lang="EN-US">FT</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">布局目前无法获取）</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l3 level1 lfo1; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">6、<span style="FONT: 7pt 'Times New Roman'">  </span></span>
				</span>
				<span lang="EN-US">FreeType2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是否兼容</span>
				<span lang="EN-US">FreeType 1.x</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">？</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt">
				<span lang="EN-US">FreeType2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不直接兼容</span>
				<span lang="EN-US">FreeType 1.x</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，但是我们可以提供一个二进制兼容层使得应用程序重链接到新版本。我们最终放弃了这种想法因为两个版本可以共存在一个系统中。（没有命名冲突）</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt">
				<span lang="EN-US">FT2 API</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">比</span>
				<span lang="EN-US">1.x</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">简单且强大，所以我们鼓励你采用新版本，这样可以使你减少很多不必要的工作。</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l3 level1 lfo1; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">7、<span style="FONT: 7pt 'Times New Roman'">  </span></span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是否可以使用</span>
				<span lang="EN-US">FreeType2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">编辑字体或者创建新字体？</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">答案是明确的：不可以。因为该库设计明确，用较少代码和内存<i style="mso-bidi-font-style: normal">读取</i>字体文件。所以我们不打算以任何方式在字体引擎里面支持编辑或者创建功能，因为这样将导致整个代码重写。这并不意味我们将来不会引入字体编辑</span>
				<span lang="EN-US">/</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">创建功能库，这取决于需求（或者说有多少人愿意为此买单）。</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在我们正式发布前不要在这方面进行揣测，对我们而言这个项目存在其他一些更重要的部分需要解决（像文字布局、文本缓存）。</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">编译</span>
				<span lang="EN-US">&amp;</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">配置</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo5; tab-stops: list 18.0pt">
				<span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'">
						<span style="mso-list: Ignore">1、<span style="FONT: 7pt 'Times New Roman'">  </span></span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如何编译</span>
				<span lang="EN-US">FreeType2</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">库？</span>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以采取多种编译方式，在</span>
				<i style="mso-bidi-font-style: normal">
						<span lang="EN-US">freetype2/docs/build</span>
				</i>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下有详细说明文档。</span>
		</p>
		<p>
				<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">这里介绍最简单的基于</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">VS IDE</span>
				<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">的编译方式。</span>
				<i style="mso-bidi-font-style: normal">
						<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">freetype\builds\win32\visualc</span>
				</i>
				<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">下有</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">VC6</span>
				<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">和</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">VC7.1</span>
				<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">的工作区文件。</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">VC6</span>
				<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">打开后直接编译，有几个警告。<br /><br /><br /><br />光看或许无法到感性认识，于是来两个demo。网上比较少，我是参考nehe教程写的。总体来说会简单使用了，如果想深入了解怕是非看他的document不可。<br />简单使用示例</span>
		</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">FT_Library    pFTLib        </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    FT_Face        pFTFace        </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    FT_Error    error        </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> Init FreeType Lib to manage memory</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">    error </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> FT_Init_FreeType(</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">pFTLib);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">(error)<br /><img id="Codehighlighter1_163_247_Open_Image" onclick="this.style.display='none'; Codehighlighter1_163_247_Open_Text.style.display='none'; Codehighlighter1_163_247_Closed_Image.style.display='inline'; Codehighlighter1_163_247_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_163_247_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_163_247_Closed_Text.style.display='none'; Codehighlighter1_163_247_Open_Image.style.display='inline'; Codehighlighter1_163_247_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />    </span>
				<span id="Codehighlighter1_163_247_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_163_247_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        pFTLib </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        printf(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">There is some error when Init Library<img src="http://www.cppblog.com/images/dot.gif" /></span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />    }</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> create font face from font file</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">    error </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> FT_New_Face(pFTLib, </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">C:\\WINDOWS\\Fonts\\arial.ttf</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">pFTFace);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">!</span>
				<span style="COLOR: #000000">error)<br /><img id="Codehighlighter1_381_1170_Open_Image" onclick="this.style.display='none'; Codehighlighter1_381_1170_Open_Text.style.display='none'; Codehighlighter1_381_1170_Closed_Image.style.display='inline'; Codehighlighter1_381_1170_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_381_1170_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_381_1170_Closed_Text.style.display='none'; Codehighlighter1_381_1170_Open_Image.style.display='inline'; Codehighlighter1_381_1170_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />    </span>
				<span id="Codehighlighter1_381_1170_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_381_1170_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        FT_Set_Char_Size(pFTFace, </span>
						<span style="COLOR: #000000">16</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">6</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">16</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">6</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">300</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">300</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        FT_Glyph    glyph;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> load glyph 'C'</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">        FT_Load_Glyph(pFTFace, FT_Get_Char_Index(pFTFace, </span>
						<span style="COLOR: #000000">67</span>
						<span style="COLOR: #000000">), FT_LOAD_DEFAULT);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        error </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> FT_Get_Glyph(pFTFace</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">glyph, </span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000">glyph);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">(</span>
						<span style="COLOR: #000000">!</span>
						<span style="COLOR: #000000">error)<br /><img id="Codehighlighter1_612_1109_Open_Image" onclick="this.style.display='none'; Codehighlighter1_612_1109_Open_Text.style.display='none'; Codehighlighter1_612_1109_Closed_Image.style.display='inline'; Codehighlighter1_612_1109_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_612_1109_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_612_1109_Closed_Text.style.display='none'; Codehighlighter1_612_1109_Open_Image.style.display='inline'; Codehighlighter1_612_1109_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
						<span id="Codehighlighter1_612_1109_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_612_1109_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000"> convert glyph to bitmap with 256 gray</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">            FT_Glyph_To_Bitmap(</span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000">glyph, ft_render_mode_normal, </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            FT_BitmapGlyph    bitmap_glyph </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> (FT_BitmapGlyph)glyph;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            FT_Bitmap</span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000">    bitmap </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> bitmap_glyph</span>
								<span style="COLOR: #000000">-&gt;</span>
								<span style="COLOR: #000000">bitmap;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> i</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">; i</span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000">bitmap.rows; </span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">i)<br /><img id="Codehighlighter1_858_1046_Open_Image" onclick="this.style.display='none'; Codehighlighter1_858_1046_Open_Text.style.display='none'; Codehighlighter1_858_1046_Closed_Image.style.display='inline'; Codehighlighter1_858_1046_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_858_1046_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_858_1046_Closed_Text.style.display='none'; Codehighlighter1_858_1046_Open_Image.style.display='inline'; Codehighlighter1_858_1046_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
								<span id="Codehighlighter1_858_1046_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_858_1046_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
										<span style="COLOR: #0000ff">for</span>
										<span style="COLOR: #000000">(</span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> j</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">; j</span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000">bitmap.width; </span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">j)<br /><img id="Codehighlighter1_902_1022_Open_Image" onclick="this.style.display='none'; Codehighlighter1_902_1022_Open_Text.style.display='none'; Codehighlighter1_902_1022_Closed_Image.style.display='inline'; Codehighlighter1_902_1022_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_902_1022_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_902_1022_Closed_Text.style.display='none'; Codehighlighter1_902_1022_Open_Image.style.display='inline'; Codehighlighter1_902_1022_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />                </span>
										<span id="Codehighlighter1_902_1022_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_902_1022_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    </span>
												<span style="COLOR: #008000">//</span>
												<span style="COLOR: #008000"> if it has gray&gt;0 we set show it as 1, o otherwise</span>
												<span style="COLOR: #008000">
														<br />
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												</span>
												<span style="COLOR: #000000">                    printf(</span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">%d</span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">, bitmap.buffer[i</span>
												<span style="COLOR: #000000">*</span>
												<span style="COLOR: #000000">bitmap.width</span>
												<span style="COLOR: #000000">+</span>
												<span style="COLOR: #000000">j]</span>
												<span style="COLOR: #000000">?</span>
												<span style="COLOR: #000000">1</span>
												<span style="COLOR: #000000">:</span>
												<span style="COLOR: #000000">0</span>
												<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />                }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                printf(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">\n</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000"> free glyph</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">            FT_Done_Glyph(glyph);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            glyph </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> free face</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">        FT_Done_Face(pFTFace);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        pFTFace </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />    }</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> free FreeType Lib</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">    FT_Done_FreeType(pFTLib);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    pFTLib </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> NULL;</span>
		</div>
<img src ="http://www.cppblog.com/HUUYUU/aggbug/14985.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/HUUYUU/" target="_blank">HUYU</a> 2006-11-10 23:00 <a href="http://www.cppblog.com/HUUYUU/archive/2006/11/10/14985.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>从笑话中悟出C++开发管理之"道" </title><link>http://www.cppblog.com/HUUYUU/archive/2006/10/30/14352.html</link><dc:creator>HUYU</dc:creator><author>HUYU</author><pubDate>Mon, 30 Oct 2006 00:49:00 GMT</pubDate><guid>http://www.cppblog.com/HUUYUU/archive/2006/10/30/14352.html</guid><wfw:comment>http://www.cppblog.com/HUUYUU/comments/14352.html</wfw:comment><comments>http://www.cppblog.com/HUUYUU/archive/2006/10/30/14352.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/HUUYUU/comments/commentRss/14352.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/HUUYUU/services/trackbacks/14352.html</trackback:ping><description><![CDATA[
		<p>1. 程序员写出自认为没有Bug的代码。 </p>
		<p>2. 软件测试，发现了20个Bug。 </p>
		<p>3. 程序员修改了10个Bug，并告诉测试组另外10个不是Bug。 </p>
		<p>4. 测试组发现其中5个改动根本无法工作，同时又发现了15个新Bug。 </p>
		<p>5. 重复3次步骤3和步骤4。 </p>
		<p>6. 鉴于市场方面的压力，为了配合当初制定的过分乐观的发布时间表，产品终于上市了。 </p>
		<p>7. 用户发现了137个新Bug。 </p>
		<p>8. 已经领了项目奖金的程序员不知跑到哪里去了。 </p>
		<p>9. 新组建的项目组修正了差不多全部137个Bug，但又发现了456个新Bug。 </p>
		<p>10. 最初那个程序员从斐济给饱受拖欠工资之苦的测试组寄来了一张明信片。整个测试组集体辞职. </p>
		<p>11. 公司被竞争对手恶意收购。收购时，软件的最终版本包含783个Bug。 </p>
		<p>12. 新CEO走马上任。公司雇了一名新程序员重写该软件。 </p>
		<p>13. 程序员写出自认为没有Bug的代码。 </p>
		<p>　　要我说，如果真有这样的公司，不倒闭对不起人民。 </p>
		<p>　这个笑话从程序员开始，到程序员结束，从头到尾都在说程序员的不是。但是我要说的是，这完全是管理者的失败，从整个过程中，看不到任何管理工作。这种管理者不但无知无能，还很无耻——将自己的失败责任推给程序员。 </p>
		<p>　1、程序员凭什么证明他的代码没有BUG？有Test case吗？有Code review吗？这个环节管理缺失。 </p>
		<p>　2、测试发现BUG有进行BUG管理吗？有跟踪吗？这个环节管理缺失。<br />　3、凭什么证明程序员已经把那10个BUG修改好了？另10个又为什么不是BUG？BUG的评价标准难道是程序员说了算？这个环节管理缺失。 </p>
		<p>　4、5个不能工作的BUG修改问题有没有追究责任？增加新BUG是修改过程中不可避免的事情，但是如果有有效的单元测试机制，可以大大减少这种情况。这个环节管理缺失。 </p>
		<p>　5、迭代是正常的，但是问题处理于发散而不是收敛发展，可见没有有效的管理调控。这个环节管理缺失。 </p>
		<p>　6、过于乐观的时间表和不可能达到的最后期限，都表现出管理者的无知和无能。而在这样的情况下强行推出产品，那就是无知者无畏了。 </p>
		<p>　7、这是对用户的不负责任，管理者要负最大的责任。 </p>
		<p>　8、这样的情况还能发项目奖金，只能说管理者不是一般的愚蠢。 </p>
		<p>　9、管理工作没有任何的改进，问题仍然处于发散迭代状态。管理工作依然没有到位。 </p>
		<p>　10、拖欠测试部门工资体现出管理者对质量管理工作的忽视以及对人力资源管理方面一无所知。 </p>
		<p>　11、送被收购者两个字：活该。送收购者两个字：瞎眼。 </p>
		<p>　12、可见新管理者与原管理者半斤八两，都没有认识到问题的根本所在。不过也只有这样的管理者才会作出收购这种公司的决策。 </p>
		<p>　13、历史的重演是必然的。 </p>
		<p>　一个正常的企业或是项目，其运作必须应该是循环向上进行的。而保障这种运行的工作就是管理。而管理工作的主要内容就是控制，包括控制循环的节奏——不能太快也不能太慢，控制发展的方向——只能向上不能向下，控制运作的稳定——不能大起大落或时聚时散等。<br />　而这一切，在这个例子中都看不到。 </p>
		<p>　在这个笑话的例子中，一切都是以开发工作在驱动，这首先就是一个方向性错误，产品是为用户服务的，当然应该是以用户和市场作为驱动，并且结合自身的能力最终 确定工作的重点。这一错误折射出管理者对被管理的内容很不了解，只好任由比较了解的程序员摆布——事实上他们除了技术，并不会了解更多。 </p>
		<p>　一个管理者如果对自己所管理的内容不了解，他就不可能管理得好。 </p>
		<p>　这是一件毫无疑问的事，可是国内的软件业似乎总是不相信这一点。中国软件业中流毒最深的谎言之一就是： </p>
		<p>　管理者只要懂管理就可以，不需要懂技术。 </p>
		<p>其实这不过是那些无知无能无耻的管理者为了骗钱而编出来的，相信这句话的人必将付出金钱的代价。 </p>
		<p>　其次是质量管理。基本的质量管理常识告诉我们，每次循环结束前，最重的工作就是总结改进。只有这样才能保证循环运作是向上发展，而不是失去控制地向下发展。 也只有有效的质量管理，才能保证迭代过程是收敛发展，并最终达到目标。但在这个例子中，这个部分显然是缺失的——其中虽然有测试部门，但是他们的作用仅仅 是质量管理中的质量检测环节，管理部分还是缺失的。 </p>
		<p>　然后是人力资源管理。软件开发是一项劳动密集型的工作，虽然这是脑力劳动，但同样意味着人在因素在其中占有决定性的地位。而例子中未改完BUG的程 序员拿到项目奖金，而同样辛苦工作的测试人员却被拖欠薪资，除了表现出管理者对他们的工作内容的不了解，以及对质量管理工作的不重视以外，还表现出管理者 完全不会管人，这是一种谋杀团队的行为——谋杀一个团队远比建设要容易得多。 </p>
		<p>　最后，这个失败的管理者把他的经历编成这个笑话，让大家看到他被程序员们害得多惨，把程序员妖魔化为一群骗子。但只要稍懂管理的人简单分析一下就可以看出来，只不过是这个人的无知和无能造成了他现在的结果，而把责任推给别人的行为更是表现出他的无耻。 </p>
		<p>　作为身居高位的管理者，如果连应该承担的责任都要推卸，他们还能胜任什么事情呢? </p>
<img src ="http://www.cppblog.com/HUUYUU/aggbug/14352.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/HUUYUU/" target="_blank">HUYU</a> 2006-10-30 08:49 <a href="http://www.cppblog.com/HUUYUU/archive/2006/10/30/14352.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关注对TinyXML的应用</title><link>http://www.cppblog.com/HUUYUU/archive/2006/10/13/13638.html</link><dc:creator>HUYU</dc:creator><author>HUYU</author><pubDate>Fri, 13 Oct 2006 05:56:00 GMT</pubDate><guid>http://www.cppblog.com/HUUYUU/archive/2006/10/13/13638.html</guid><wfw:comment>http://www.cppblog.com/HUUYUU/comments/13638.html</wfw:comment><comments>http://www.cppblog.com/HUUYUU/archive/2006/10/13/13638.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/HUUYUU/comments/commentRss/13638.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/HUUYUU/services/trackbacks/13638.html</trackback:ping><description><![CDATA[关注对TinyXML的应用<br /><a href="http://sourceforge.net/projects/tinyxml/"><font color="#3f3f9f">http://sourceforge.net/projects/tinyxml/<br /></font></a><img src ="http://www.cppblog.com/HUUYUU/aggbug/13638.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/HUUYUU/" target="_blank">HUYU</a> 2006-10-13 13:56 <a href="http://www.cppblog.com/HUUYUU/archive/2006/10/13/13638.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>strlen &amp; strcmp</title><link>http://www.cppblog.com/HUUYUU/archive/2006/10/04/13288.html</link><dc:creator>HUYU</dc:creator><author>HUYU</author><pubDate>Tue, 03 Oct 2006 16:02:00 GMT</pubDate><guid>http://www.cppblog.com/HUUYUU/archive/2006/10/04/13288.html</guid><wfw:comment>http://www.cppblog.com/HUUYUU/comments/13288.html</wfw:comment><comments>http://www.cppblog.com/HUUYUU/archive/2006/10/04/13288.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/HUUYUU/comments/commentRss/13288.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/HUUYUU/services/trackbacks/13288.html</trackback:ping><description><![CDATA[
		<p>unsigned int strlenW(const wchar_t *wcs)<br />{<br /> const wchar_t *eos = wcs;</p>
		<p> while (*eos)<br />     ++eos;</p>
		<p> return eos-wcs;<br />}</p>
		<p>
				<br />int strcmpW(const wchar_t *pwc1, const wchar_t *pwc2)<br />{<br /> int ret = 0;</p>
		<p> while ( !(ret = *pwc1 - *pwc2) &amp;&amp; *pwc2)<br />  ++pwc1, ++pwc2;<br /> return ret;<br />}<br /></p>
<img src ="http://www.cppblog.com/HUUYUU/aggbug/13288.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/HUUYUU/" target="_blank">HUYU</a> 2006-10-04 00:02 <a href="http://www.cppblog.com/HUUYUU/archive/2006/10/04/13288.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何识别字符串的编码？</title><link>http://www.cppblog.com/HUUYUU/archive/2006/10/04/13287.html</link><dc:creator>HUYU</dc:creator><author>HUYU</author><pubDate>Tue, 03 Oct 2006 16:01:00 GMT</pubDate><guid>http://www.cppblog.com/HUUYUU/archive/2006/10/04/13287.html</guid><wfw:comment>http://www.cppblog.com/HUUYUU/comments/13287.html</wfw:comment><comments>http://www.cppblog.com/HUUYUU/archive/2006/10/04/13287.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/HUUYUU/comments/commentRss/13287.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/HUUYUU/services/trackbacks/13287.html</trackback:ping><description><![CDATA[
		<div class="postbody">如果哪一天你的程序收到一段不明编码的字符串，或者别人给了一个你看不懂的文本文件，你应该如何去识别字符串的编码呢？<br /><br />一种是程序中用的方法，可以使用ICU之类的库来帮你识别，如果你的字符串越长，它所能猜到的概率就越大。<br /><br />另外一种方法是使用IE来帮助你查看。使用IE打开不明编码的文件，然后选择Encoding，不停的切换编码，基本上看起来像文字的时候，就是那个编码了:).这个方法很简单，比较实用。<br /><br />另外对于unicode的编码，观察其BOM，也有助于你去猜测编码。<br />UTF-8: <strong>EF BB BF</strong> E6 B5 8B E8 AF 95 31 32 33 34<br />UTF-16: <strong>FF FE</strong> 4B 6D D5 8B 31 00 32 00 33 00 34 00<br />UTF-16 Big endian : <strong>FE FF</strong> 6D 4B 8B D5 00 31 00 32 00 33 00 34<br /><br /><br />最后附上两个小工具，能帮你生成各种文字的字符和识别字符在不同code page下的编码。just have fun<br /><br /><a href="/Files/sandy/encoding_tools.rar">http://www.cppblog.com/Files/sandy/encoding_tools.rar</a><br /></div>
<img src ="http://www.cppblog.com/HUUYUU/aggbug/13287.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/HUUYUU/" target="_blank">HUYU</a> 2006-10-04 00:01 <a href="http://www.cppblog.com/HUUYUU/archive/2006/10/04/13287.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>c++中的string用法(三)</title><link>http://www.cppblog.com/HUUYUU/archive/2006/09/04/12018.html</link><dc:creator>HUYU</dc:creator><author>HUYU</author><pubDate>Mon, 04 Sep 2006 10:49:00 GMT</pubDate><guid>http://www.cppblog.com/HUUYUU/archive/2006/09/04/12018.html</guid><wfw:comment>http://www.cppblog.com/HUUYUU/comments/12018.html</wfw:comment><comments>http://www.cppblog.com/HUUYUU/archive/2006/09/04/12018.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/HUUYUU/comments/commentRss/12018.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/HUUYUU/services/trackbacks/12018.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: basic_string::max_size																																						返回string 能放的最大元素个数。（不同于capacity）																														size										_										type max										_								...&nbsp;&nbsp;<a href='http://www.cppblog.com/HUUYUU/archive/2006/09/04/12018.html'>阅读全文</a><img src ="http://www.cppblog.com/HUUYUU/aggbug/12018.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/HUUYUU/" target="_blank">HUYU</a> 2006-09-04 18:49 <a href="http://www.cppblog.com/HUUYUU/archive/2006/09/04/12018.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>