代码改变世界

常见C语言库函数源码

2011-08-18 15:19 by Daniel Zheng, 2244 阅读, 1 推荐, 收藏, 编辑
摘要:memcpy和memmove功能基本上差不多,但是当源串和目标串有Overlap时,memmove可以正确处理,memcpy则不行。void * __cdecl memcpy (void * dst, const void * src, size_t count){ void * ret = dst; while (count--) { *(char *)dst = *(char *)src; dst = (char *)dst + 1; src = (char *)src + 1; } return(ret);}void * __cdecl memmove (void * dst, cons 阅读全文

第一个 Python 程序

2011-08-16 23:22 by Daniel Zheng, 1670 阅读, 0 推荐, 收藏, 编辑
摘要:这是一个完整的, 可执行的 Python 程序。def buildConnectionString(params): """Build a connection string from a dictionary of parameters. Returns string.""" return ";".join(["%s=%s" % (k, v) for k, v in params.items()])if __name__ == "__main__": myParams = 阅读全文

More Effective C++ 学习笔记(1)

2011-08-16 17:13 by Daniel Zheng, 491 阅读, 0 推荐, 收藏, 编辑
摘要:不要对数组使用多态 类继承的最重要的特性是你可以通过基类指针或引用来操作派生类。这样的指针或引用具有行为的多态性,就好像它们同时具有多种形态。C++允许你通过基类指针和引用来操作派生类数组。不过这根本就不是一个特性,因为这样的代码几乎从不如你所愿地那样运行。假设你有一个类BST(比如是搜索树对象)和继承自BST类的派生类BalancedBST:class BST { ... };class BalancedBST: public BST { ... }; 有这样一个函数,它能打印出BST类数组中每一个BST对象的内容:void printBSTArray(ostream& s, con 阅读全文

Understanding Smart Pointers

2011-08-15 23:10 by Daniel Zheng, 315 阅读, 0 推荐, 收藏, 编辑
摘要:C++ programmers do not necessarily need to use plain pointer types when managing memory on the heap (or the free store); they can make use of smarter option.What Are Smart Pointers?Very simply said, a smart pointer in C++ is a class, with overloaded operators, which behaves like a conventional point 阅读全文

Working with Bit Flags Using STL

2011-08-15 12:39 by Daniel Zheng, 278 阅读, 0 推荐, 收藏, 编辑
摘要:Bits can be very efficient way of storing settings and flags. STL supplies classes that help organize and manipulate bitwise information.The bitset Classstd::bitset is an STL class designed for handling information in bits and bit flags. The std::bitset is not classified as an STL container because 阅读全文

Adaptive Container: stack and queue

2011-08-14 22:53 by Daniel Zheng, 315 阅读, 0 推荐, 收藏, 编辑
摘要:The standard template library (STL) features containers that adapt othersto simulate stack and queue behavior. Such containers that internally useanother and present a distinct behavior are called adaptive containers.Using the STL stack ClassThe STL stack is a generic class that allows insertions an 阅读全文

STL Algorithms

2011-08-14 20:25 by Daniel Zheng, 345 阅读, 0 推荐, 收藏, 编辑
摘要:One important part of the standard template library is a set of generic functions, supplied by the header <algorithm>. that help manipulate or work with the contents of a container.What Are STL Algorithms?Finding, searching, removing, and counting are some generic algorithmic activities that f 阅读全文

Understanding Function Objects

2011-08-13 00:24 by Daniel Zheng, 301 阅读, 0 推荐, 收藏, 编辑
摘要:Function objects or functors might sould exotic or intimidating, but they are entities of C++ that you have probably seen if not also used, without having realized it.The Concept of Function Objects and PredicateOn a conceptual level, function objects are objects that work as function. On an impleme 阅读全文

STL map and multimap

2011-08-12 10:02 by Daniel Zheng, 392 阅读, 0 推荐, 收藏, 编辑
摘要:A Brief IntroductionThe map and multimap are key-value pair containers that allow for a lookup on the basis of a key. The difference between the map and multimap is that only the latter allows for duplicates, whereas the former can store only unique keys.Th facilitate quick searching, STL implementa 阅读全文

STL set and multiset

2011-08-11 23:48 by Daniel Zheng, 378 阅读, 1 推荐, 收藏, 编辑
摘要:The set and multiset are containers that facilitate a quick lookup of keys in a container that stores them; that is, the keys are the values stored in the one-dimensional container.The difference between the set and the multiset is that latter allows for duplicates whereas the former can store only 阅读全文