摘要: 上一篇文章介绍了 CRT Memory Detection 的概念和基本用法, 那么这篇文章将介绍一种高级调试技术 --- memory allocation breakpoints. ( 以下讨论均在 debug 模式前提下 )基本概念:首先让回顾一下完整的 memory dump 的输出格式:其... 阅读全文
posted @ 2014-08-22 18:37 walfud 阅读(322) 评论(0) 推荐(0) 编辑
摘要: CRT 有一个非常好用的, 检测 mem leak 的子系统, 下面介绍一下它的用法. msdn 官网 doc:http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx(msdn 原文中有一些谬误, 我经过自己的实践发现和其描述不符, 请见下文 'm... 阅读全文
posted @ 2014-08-20 16:53 walfud 阅读(752) 评论(0) 推荐(0) 编辑
摘要: 2014/7/16 日晚, 第一次做了梦中梦.此前, 我一直认为, 人在梦中是无法说出 "梦" 这个字的(不信你试试, 然后给我留言). 而且很长一段时间, 我还为自己的新发现而感到子豪. 直到这一晚, 我印象很深:我做了一个梦, 因为在梦中我隐约能感觉到逻辑的混乱, 因此梦醒后.我就想: "嗯, ... 阅读全文
posted @ 2014-07-18 09:55 walfud 阅读(219) 评论(1) 推荐(0) 编辑
摘要: 正常人应该读一读, 冲破思维的禁锢, 急转思维惯性. 阅读全文
posted @ 2014-07-15 10:16 walfud 阅读(1020) 评论(0) 推荐(0) 编辑
摘要: 小摊上买了半块西瓜, 用保鲜膜抱着. 拿到家里后, 欲吃之. 正在揭开保鲜膜的一刹那, 经常听到长辈大声的嘱咐道: "注意点儿! 保鲜膜别撕坏了, 一会儿还得盖回去呢…”. 于是, 小心翼翼的拿下保鲜膜, 生怕给弄破了... 切了几刀后, 又把已经打了褶子的保鲜膜, 小心翼翼的舒展开. ... 阅读全文
posted @ 2014-07-08 15:38 walfud 阅读(339) 评论(0) 推荐(0) 编辑
摘要: 简单地说, /gs 选项就是打开 stack guard 功能, 也就是在 call 一个函数, 进行压栈的过程中, 在 ebp 和 local variables 中间, 插入一个 global cookie. 一旦 local variable 发生了溢出, 改写了 stack guard 的值... 阅读全文
posted @ 2014-05-08 10:36 walfud 阅读(1285) 评论(0) 推荐(0) 编辑
摘要: 设置 JIT debugger:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug REG_SZ: Auto : 1REG_SZ: Debugger : "c:\windbg.exe"... 阅读全文
posted @ 2014-03-24 10:18 walfud 阅读(605) 评论(0) 推荐(0) 编辑
摘要: // // 本段代码不可作为工业生产只用. 因为多生产者-消费者模型中, 必须要考虑到 '生产者-生产者'/'消费者-消费者' 互斥问题, 以及生产者生产速度不一致导致的跳跃完成生产而消费者顺序消费导致的重复消费问题.int proCount = 0, conCount = 0;#define bufSize 5int buffer[bufSize] = {};HANDLE empty = CreateSemaphore(nullptr, bufSize, bufSize, nullptr), // 空闲的位置. full = CreateSemaphore(n 阅读全文
posted @ 2014-02-10 16:58 walfud 阅读(501) 评论(0) 推荐(1) 编辑
摘要: 3.13.5谨防 "我们向来这么做" 这种自以为有力的说法. 有这样一个故事, Beth 想按照她丈夫家祖传的广受好评的炖肉菜谱来做一锅炖肉. 她丈夫 Adbul 说, 他母亲是这样教他的: "先撒上盐和胡椒, 然后去头去尾, 最后放到平底锅里盖上盖子炖." Beth 就问了: "为什么要去头去尾?" Adbul 回答说: "我不知道, 我向来这么做. 这得问一下我母亲." 他打电话给母亲, 母亲说: "我不知道, 我向来这么做. 这得问一下你祖母." 他母亲打电话问祖母, 祖母回答说: &qu 阅读全文
posted @ 2013-12-27 22:52 walfud 阅读(417) 评论(0) 推荐(0) 编辑
摘要: `CString` is a powerful utility in our daily programming. But recently I found something intuitive and error prone.I have such task: To make sure the file path is end with `360sd`, such as 'c:\program files' -> 'c:\program files\360sd'; but 'c:\program files\360sd' will ke 阅读全文
posted @ 2013-11-08 18:17 walfud 阅读(254) 评论(0) 推荐(0) 编辑
摘要: Bug version: // FILETIME ft = ....; ULONGLONG res = ft.dwHighDateTime (ft.dwHighDateTime) `ft.dwHighDateTime << 0x00000000, 00000020`.You can notice, the right operand is expanded to 64-bit, which is bug prone!The operation `<<` will not promote the left operand however there is overflow 阅读全文
posted @ 2013-10-05 11:35 walfud 阅读(297) 评论(0) 推荐(0) 编辑
摘要: for (int i = 0; i < 30; ++i) { // Do something other. foo(); bar(); baz(); // ... if (/* Some condition */) { // 满足 xxx 条件, 退出循环. i = INT_MAX; } }这段简短的代码中, 隐藏着一个 bug.当 Some Condition 满足条件时, `i = INT_MAX` 会执行, 此时作... 阅读全文
posted @ 2013-10-04 10:43 walfud 阅读(338) 评论(0) 推荐(0) 编辑
摘要: 声明: 所有图片均为我在腾讯博客的原创, 但是从我的腾讯微博转过来就被流氓的打了标签. 因此不涉及版权问题, 可以随意使用.C++11 中弃用了 `throw(type1, type2...)` 这种异常声明方式. 但是库中大量使用了 noexcept 代替原有异常机制, 因此提高了库的效率.默认析构函数是 noexcept(true) 的, 但是如果基类析构函数是 noexcept(false), 那么自雷析构函数默认也是 noexcept(false) 的.类中成员变量的初始化顺序: 1, 就地初始化. 2, 初始化列表. 3, 构造函数体. (目前, 最新的 vs2013 preview 阅读全文
posted @ 2013-09-01 10:30 walfud 阅读(8380) 评论(0) 推荐(1) 编辑
摘要: OutputDebugString 是很常用的调试函数, 起作用是将参数的字符串, 在运行时输出到特定的位置, 以便我们能都获知程序执行的情况. 其 MSDN:http://msdn.microsoft.com/en-us/library/windows/apps/aa363362(v=vs.85).aspx其中比较重要的两点:1.Applications should send very minimal debug output...2.OutputDebugStringWconverts the specified string based on the current system lo 阅读全文
posted @ 2013-08-27 21:28 walfud 阅读(5033) 评论(0) 推荐(0) 编辑
摘要: C++11 提供了一些便利的语法, 不一定能改变世界, 但是真的改变了 C++ coder 的生活. 然后 C++ coder 占据了程序员的很大一部分, 所以 C++11 这些便利的语法, 也间接地改变了世界.排名第一: lambda expression. 第二: range-based for loop. 第三: initializer list. 第四: user-defined literal注:1. 排名是我自己排的.2. 下文所说的 "传统 C++" 一般指 C++03, 以及更老的 C++ 标准.lambda expression曾几何时, 我们总是要为 f 阅读全文
posted @ 2013-08-25 17:38 walfud 阅读(1158) 评论(0) 推荐(0) 编辑
摘要: 我们使用的大部分 PC 是基于 Intel微处理器的 x86 和 x64 架构计算机.因此, 我们面对的 windows 避免不了和 Intel 架构有些设计上的契合. 比如接下来要说到的内存管理.为简单起见, 我们只讨论 x86 体系架构的内存管理. 不考虑换页文件影响.进程的内存图 1 (本图摘自 ref 2)对于系统中的每一个进程而言, 都有 4GB 的 "内存空间". 也就是每个进程都认为自己有 4GB 的内存可以使用.系统将每个进程的 4GB 地址空间, 从逻辑上划分为两大部分: a)蓝色的是用户空间, 此空间是被用户程序所使用的. 比如我在代码中写 " 阅读全文
posted @ 2013-08-13 23:34 walfud 阅读(24418) 评论(3) 推荐(7) 编辑
摘要: Recently, I made a test about retriving calculate the CPU usage of the specified process. In common, we have following steps:1. a)Get process time at this point(proc_A). b) Get system time the this point(sys_A).2. Sleep for a while.3. a)Get process time at this point(proc_B). b) Get system time ... 阅读全文
posted @ 2013-08-08 21:07 walfud 阅读(3178) 评论(0) 推荐(0) 编辑
摘要: 微软的 takeown 命令的核心实现:http://msdn.microsoft.com/en-us/library/windows/desktop/aa379620(v=vs.85).aspx其中有个导入函数 `SetPrivilege`, 实现:http://msdn.microsoft.com/en-us/library/windows/desktop/aa446619(v=vs.85).aspx总结来说就两步:1. 给当前进程赋予 `SE_TAKE_OWNERSHIP_NAME` 权限. 这个特权可以修改目标文件的 ownership. (`SetPrivilege`)2. 给目标文 阅读全文
posted @ 2013-08-07 10:07 walfud 阅读(266) 评论(0) 推荐(0) 编辑
摘要: Let's see the piece of code below:Obviously, `foo(false)` will call `foo(bool)` as excepted.But do you know what does `foo("1234")` actually select? The answer is `foo(bool)` too! See here for detail:http://stackoverflow.com/questions/13268608/boostvariant-why-is-const-char-converted-t 阅读全文
posted @ 2013-08-04 13:00 walfud 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 本打算在之前一篇讲基础的博客里继续写的,但是考虑到篇幅不利与阅读,以及本文是针对打造 IDE 环境,所以单写一篇。不求普适。所用插件:vim =》 很多 linux 发行版都没有安装完整的 vim。请自行安装。exuberant-ctags =》这是基础插件,主要功能就是分析变量/函数符号,方便定位。其它很多插件依赖于此插件。TagList =》 高效浏览代码中的变量和函数。类似 sourceInsight 左边的 Symble 窗口。WinManager =》 文... 阅读全文
posted @ 2013-07-13 14:07 walfud 阅读(353) 评论(0) 推荐(0) 编辑
摘要: 1. 对于 mbs(multi-byte-string) 而言, 在 string 中的 size 返回的是所占字节的大小.2. 某些字符 mbs 是无法表示的. 比如 “𪚥” 这样字符. Vs 2008/2012 中的 mbs(std::string 以及 vc 9 中 atl 的 CString), 对于无法转换的字符都以 3f 填充. 下图以 std::string 为例.3. 之前发的连接中给的算法是对的: http://blog.csdn.net/wallaceli1981/article/details/5740618对于 wcstombs 需要 4 倍于原 wcs 阅读全文
posted @ 2013-06-22 15:47 walfud 阅读(2102) 评论(1) 推荐(0) 编辑
摘要: 原问题出处:http://blog.csdn.net/wyhuan1030/article/details/5100372我在此仅作回答字符串学习时间:1.5W(“W”周,下同)知识点checklist问:1. strlen()函数的返回值是什么类型的?2. 字符串strlen()的值,是否和他占据的内存空间相同?3. 你是否知道strcpy函数存在的潜在风险?如何避免?4. 如果一个字符串没有字符串结束符,而调用str开头的库函数,会发生什么?5. Strcpy(),strcat(),strcmp(),strncpy(),strncat(),strncmp()内部到底是如何运行的?这些函数到 阅读全文
posted @ 2013-04-18 10:23 walfud 阅读(483) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2013-04-09 09:58 walfud 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 转:http://blog.csdn.net/regionyu/article/details/1708072 阅读全文
posted @ 2013-03-25 14:51 walfud 阅读(441) 评论(0) 推荐(0) 编辑
摘要: 转: http://blog.csdn.net/regionyu/article/details/1708084INT(hex)AH功能调用参数返回参数100设置显示方式 AL=00 40×25黑白方式AL=01 40×25彩色方式AL=02 80×25黑白方式AL=03 80×25彩色方式AL=04 320×200彩色图形方式AL=05 320×200黑白图形方式AL=06 320×200黑白图形方式AL=07 80×25单色文本方式AL=08 160×200 16色图形 (PCjr)AL=09 320 阅读全文
posted @ 2013-03-25 14:49 walfud 阅读(1352) 评论(0) 推荐(0) 编辑
摘要: bool foo() { unsigned int a = 6; int b = -20; // If 'b' is 'long long'? return a + b < 6 ? true : false; } If 'int b = -20;', the result is false, because 'a + b' => (unsigned + int) => (unsigned + unsigned) in integral promotion. Thus result is unsigned(-14) 阅读全文
posted @ 2013-02-19 17:57 walfud 阅读(291) 评论(0) 推荐(0) 编辑
摘要: class Document {};class MyDocument : public Document {};class Application{public: virtual Document *CreateDocument() = 0;};class MyApplication : public Application{public: virtual Document *CreateDocument() override { return new MyDocument; }};其中, CreateDocument 就是 Factory Method.... 阅读全文
posted @ 2013-02-16 09:43 walfud 阅读(115) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <string>#include <regex>using namespace std;int main(){ string str = "1234-abcd-!@#$"; //regex e("[^-]+"); for (auto it = sregex_iterator(str.begin(), str.end(), regex("[^-]+")); // 这里可以通过编译, 但是实际上是有问题的. it != sregex_iterato 阅读全文
posted @ 2013-02-07 15:27 walfud 阅读(809) 评论(0) 推荐(0) 编辑
摘要: class View{public: // Interface. void Display() { SetFocus(); DoDisplay(); ResetFocus(); } void SetFocus() { cout <<"View::SetFocus" <<endl; } void ResetFocus() { cout <<"View::ResetFocus" <<endl; }private: // logic. virtual void... 阅读全文
posted @ 2013-02-06 11:59 walfud 阅读(134) 评论(0) 推荐(0) 编辑
摘要: Strategy 和 State 模式极为相似, 唯一的不同就是 Strategy 侧重于对操作进行抽象, 而 State 侧重于将数据进行抽象.关于 State 模式, 请见:http://www.cnblogs.com/walfud/articles/2901855.html 阅读全文
posted @ 2013-02-06 11:33 walfud 阅读(127) 评论(0) 推荐(0) 编辑
摘要: class State{public: // Interface. virtual void foo() = 0; virtual void bar() = 0;};class StateVer0 : public State{public: // Interface. virtual void foo() override { cout foo(); } void bar() { //// Unmaintainable! //switch (m_ver) //{ //case 0: ... 阅读全文
posted @ 2013-02-06 11:06 walfud 阅读(172) 评论(0) 推荐(0) 编辑
摘要: class Originator;class Memento{ // data. int m_x, m_y; friend class Originator;private: Memento(int x, int y) : m_x(x), m_y(y) {}};class Originator{ // data. int m_x, m_y;public: Originator(int x, int y) : m_x(x), m_y(y) {}public: // Interface. void Move(int x, int y) {... 阅读全文
posted @ 2013-02-06 10:35 walfud 阅读(163) 评论(0) 推荐(0) 编辑
摘要: class AList;class AButton;class AEdit;class Director{ // data. AList *m_list; AButton *m_button; AEdit *m_edit;public: // Interface. void Init(AList *l, AButton *b, AEdit *e) { m_list = l, m_button = b, m_edit = e; } void foo_bazBar(); void bar_b... 阅读全文
posted @ 2013-02-05 18:25 walfud 阅读(138) 评论(0) 推荐(0) 编辑
摘要: template class Iterator{public: // Interface virtual void First() = 0; virtual void Next() = 0; virtual bool IsDone() const = 0; virtual T CurrentItem() const = 0;};template class DequeIterator : public Iterator{ // data. const deque &m_deque; unsigned m_curPos;public: Deq... 阅读全文
posted @ 2013-02-05 17:46 walfud 阅读(150) 评论(0) 推荐(0) 编辑
摘要: class BooleanExp{public: // Interface. virtual bool Evaluate() const = 0;};class AndExp : public BooleanExp{ // data. BooleanExp &m_booleanExpA, &m_booleanExpB;public: AndExp(BooleanExp &booleanExpA, BooleanExp &booleanExpB) : m_booleanExpA(booleanExpA), m_booleanExpB(booleanExpB) {} 阅读全文
posted @ 2013-02-01 15:44 walfud 阅读(164) 评论(0) 推荐(0) 编辑
摘要: class ReceiverA{public: // Interface. void Action() { cout Execute(); // 此时, 调用者无需区分执行的内容, 只需要调用 Execute 即可. cb->Execute(); // 此模式借助 Command 这个中间层, 在调用者 ('main' 函数) 和被调用者 ('ReceiverA' 和 'ReceiverB') 之间解耦. // TODO: Release memory. return 0;} 阅读全文
posted @ 2013-01-31 21:22 walfud 阅读(160) 评论(0) 推荐(0) 编辑
摘要: class Window{protected: Window *m_successor; bool m_msg;public: Window(Window *successor, bool msg) : m_successor(successor), m_msg(msg) {}public: // Interface. virtual void Msg() { if (m_msg) { showMsg(); } else { if (m_succ... 阅读全文
posted @ 2013-01-31 20:47 walfud 阅读(114) 评论(0) 推荐(0) 编辑
摘要: class Subject{public: // Interface. virtual void Request() = 0;};class RealSubject : public Subject{public: // Interface. virtual void Request() override { cout <<"RealSubject::Request()." <<endl; }};class Proxy : public Subject{ // data. Subject &m_subject;public: Proxy(Su 阅读全文
posted @ 2013-01-31 20:46 walfud 阅读(117) 评论(0) 推荐(0) 编辑
摘要: struct Context{ int x, y;};class FlyWeight{ // data. const string m_str;public: FlyWeight(const string &str) : m_str(str) {}public: // Interface. void draw(Context &c) { cout " <<m_str <<endl; }};int main(int argc, char *argv[]){ Context c1 = {4, 8}, c2 = {0, -4},... 阅读全文
posted @ 2013-01-29 09:41 walfud 阅读(106) 评论(0) 推荐(0) 编辑
摘要: class Component{public: virtual void Operation() = 0;};class ConcreteComponent : public Component{public: // Interface. virtual void Operation() override { cout Operation(); AddedBehavior(); }private: // logic. void AddedBehavior() { cout <<"ConcreteDecorator::AddedBehavior(... 阅读全文
posted @ 2013-01-24 17:53 walfud 阅读(136) 评论(0) 推荐(0) 编辑