1 window下新手debug时常会遇到一变量值显示为一连串“烫烫烫”,“铪铪铪”,或者”屯屯屯“的特殊内容,这个是VC使用的Magic Number,用于辅助调试用的,常见的Magic Number,如下所示:
* 0xABABABAB : Used by Microsoft's HeapAlloc() to mark "no man's land" guard bytes after allocated heap memory * 0xABADCAFE : A startup to this value to initialize all free memory to catch errant pointers * 0xBAADF00D : Used by Microsoft's LocalAlloc(LMEM_FIXED) to mark uninitialised allocated heap memory * 0xBADCAB1E : Error Code returned to the Microsoft eVC debugger when connection is severed to the debugger * 0xBEEFCACE : Used by Microsoft .NET as a magic number in resource files * 0xCCCCCCCC : Used by Microsoft's C++ debugging runtime library to mark uninitialised stack memory * 0xCDCDCDCD : Used by Microsoft's C++ debugging runtime library to mark uninitialised heap memory * 0xDEADDEAD : A Microsoft Windows STOP Error code used when the user manually initiates the crash. * 0xFDFDFDFD : Used by Microsoft's C++ debugging heap to mark "no man's land" guard bytes before and after allocated heap memory * 0xFEEEFEEE : Used by Microsoft's HeapFree() to mark freed heap memory
更详细的信息请移步Wiki:https://en.wikipedia.org/wiki/Magic_number_(programming)
2 函数调用过程详解:http://blog.youkuaiyun.com/lksodit_yiyi/article/details/8291876,知悉变量在内存中位置
预先储备的知识:
2.1 函数调用的方式:http://blog.youkuaiyun.com/yuzhiyuxia/article/details/7639387, 在调用第三方SDK的时候要注意其函数声明的方式,函数调用方式使用错误将导致栈损坏,具体原因可从函数调用过程中详解中找到(如果有兴趣可以搜下缓冲区溢出攻击).
2.2 函数传参方式 : http://blog.youkuaiyun.com/cocohufei/article/details/6143476,可以引申出:类拷贝构造函数 http://blog.youkuaiyun.com/lwbeyond/article/details/6202256,在该链接中也同时关注下深拷贝,浅拷贝; 可再引申出内存碎片: http://blog.youkuaiyun.com/xuzhonghai/article/details/7285821(程序设计时先思考怎样能访问到一个变量,进而决定该变量如何存放,数据结构如何设计) 内存池:http://blog.youkuaiyun.com/shawngucas/article/details/6574863,可以借鉴一下垃圾回收机制, java GC: http://blog.youkuaiyun.com/zhoudaxia/article/details/26579859, 如果想彻底解决资源访问,释放烦恼,看看智能指针的使用,与垃圾回收机制相同的设计思想 http://blog.youkuaiyun.com/hackbuteer1/article/details/7561235
3 理解指针:http://blog.youkuaiyun.com/mdx20072419/article/details/7814390。指针相关的四个概念:指针的类型; 指针指向的类型; 指针指向的内容; 指针本身所占据的内存区(可以思考引用的实现方式)