
C/C++
Dark-Rich
Let the code into my blood
展开
-
<climits>头文件定义的符号常量
CHAR_MIN char的最小值SCHAR_MAX signed char 最大值SCHAR_MIN signed char 最小值UCHAR_MAX unsigned char 最大值SHRT_MAX short 最大值SHRT_MIN short 最小值USHRT_MAX unsign...原创 2013-11-02 10:17:56 · 884 阅读 · 0 评论 -
简单的Windows Socket编程实例
Server(多线程)#include #include #pragma comment(lib,"ws2_32.lib")using namespace std;#define PORT 4000#define IP_ADDRESS "127.0.0.1"DWORD WINAPI ClientThread(LPVOID lpParameter){ SOCKET Clien原创 2015-02-23 12:59:09 · 898 阅读 · 0 评论 -
C/C++头文件与实现文件中的内容安排
从规模较小的程序转到比较复杂的程序,头文件与源文件中的内容组织困扰了很久,特别是头文件中该放哪些内容,到处搜索文章并进行了一次总结,如果有什么错误或者值得商榷的地方,希望大家能够不吝赐教。 引入问题:编译模式:一个程序的源代码,可以放到不同的文件进行存放,每一个源文件都是独立的,可以分别进行编译,生成程序的时候只需要将各个目标程序进行一次连接便可以了。比如在一个文件中定义了一个函数 v...原创 2015-04-12 13:52:01 · 1659 阅读 · 1 评论 -
关于提高C语言执行效率的几点
1、以空间换取时间程序的复杂度包含时间复杂度和空间复杂度,而随着计算机硬件的发展,渐渐放低了对空间复杂度的要求,在很多情况下,为了换取程序的执行效率,牺牲计算机的空间。比如字符串的相关操作、使用缓存技术等。2、算法时间复杂度更低、效率更高的算法可以提高执行效率。一个简单的例子,计算1~100这些数的和,可以循环100次,也可以直接使用求和公式,在执行效率上,是显而易见的。3、嵌入汇编汇编代码是低级语原创 2015-05-03 13:00:47 · 3705 阅读 · 0 评论 -
Linux下使用epoll函数同时处理TCP请求和UDP请求的回射服务器
#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <assert.h>#include <stdio.h>#include <unistd.h>#inc原创 2015-03-18 18:04:45 · 865 阅读 · 0 评论 -
Linux下poll函数实现多用户聊天
Client: #define _GNU_SOURCE 1#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include<arpa/inet.h>#include <assert.h>#include <stdio.h&g...原创 2015-03-16 16:31:39 · 937 阅读 · 0 评论 -
Linux下非阻塞connect
#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <stdlib.h>#include <assert.h>#include <stdio.h>#inc原创 2015-03-14 18:02:20 · 640 阅读 · 0 评论 -
Linux下同时接受普通数据和带外数据
#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <assert.h>#include <stdio.h>#include <unistd.h>#inc原创 2015-03-11 16:55:05 · 595 阅读 · 0 评论 -
Linux下利用sendfile函数传输文件
#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <assert.h>#include <stdio.h>#include <unistd.h>#include <stdlib.h>#includ原创 2015-03-09 16:08:30 · 1169 阅读 · 1 评论 -
Linux下CGI服务器基本工作原理
#include <sys/socket.h>#include <netinet/in.h>#include <assert.h>#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <errno.h>#include &a原创 2015-03-09 10:24:41 · 1089 阅读 · 0 评论 -
单片机C语言模板
单片机C语言编程模板(基础模板)[程序开始处的程序说明]/*********************************************************************************************程序名: 编写人: 编写时间: 年 月 日硬件支持: 接口说明: /****...转载 2013-11-14 01:06:36 · 826 阅读 · 0 评论 -
Singleton Pattern(单例模式)
/*Singleton.h*/#ifndef SINGLETON_H#define SINGLETON_Hclass Singleton{public: static Singleton *Instance();protected: Singleton();private: static Singleton *instance_;};#endif/*Singlet原创 2015-05-03 12:24:08 · 643 阅读 · 0 评论 -
Adapter Pattern(适配器模式)
/*Adapter.h*/#ifndef ADAPTER_H#define ADAPTER_Hclass Target{public: Target(); virtual ~Target(); virtual void Request();protected:private:};class Adaptee{public: Adaptee();原创 2015-05-11 11:36:33 · 868 阅读 · 0 评论 -
Prototype Pattern(原型模式)
/*Prototype.h*/#ifndef PROTOTYPE_H#define PROTOTYPE_Hclass Prototype{public: virtual ~Prototype(); virtual Prototype *Clone() const=0;protected: Prototype();private:};class ConcreteP原创 2015-05-06 17:02:32 · 1090 阅读 · 1 评论 -
C++命名规范
在软件开发过程中,代码的命名规范是一项很突出的内容。一套定义完整、结构清晰明了的命名规范将大大提升源代码的可读性和软件的可维护性。据考证,没有一种命名规则可以让所有的程序员都满意,程序设计教科书一般也不会指定命名规则。但是制定一套令开发组成员基本满意的命名规则,并在项目中贯彻实施,也是团队开发一项必不可少的工作。我将我的团队的实际工作中的命名规则整理如下: 第一部分:共性规则共转载 2014-04-08 13:02:11 · 603 阅读 · 0 评论 -
warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead.
使用VS2005以上版本(VS2005、VS2008、VS2010)编译在其他编译器下正常通过的C语言程序,你可能会遇到类似如下的警告提示: 引用内容warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation转载 2014-11-02 11:10:31 · 510 阅读 · 0 评论 -
创建线程后马上CloseHandle(threadhandle)起什么作用
HANDLE threadhandle = CreateThread(NULL, 0, RecvThreadProc, NULL, NULL, NULL); CloseHandle(threadhandle); 不明白为什么创建线程后,要马上把线程的句柄关闭,这样做的目的是什么? 这样做会杀掉线程吗?解答: 创建线程后返回了线程句柄,新创建的线程内核对象的使用计数是转载 2015-03-02 09:04:36 · 1560 阅读 · 0 评论 -
C/C++ 字节对齐
概念: 对齐跟数据在内存中的位置有关。如果一个变量的内存地址正好位于它长度的整数倍,他就被称做自然对齐。比如在32位cpu下,假设一个整型变量的地址为0x00000004,那它就是自然对齐的。 为什么字节需要对齐:根本原因在于CPU访问数据的效率问题。假设上面整型变量的地址不是自然对齐,比如为0x00000002,则CPU如果取它的值的话需要访问两次内存,第一次取从0x00000002-0...转载 2015-04-13 08:52:23 · 473 阅读 · 0 评论 -
AbstractFactory Pattern(抽象工厂模式)
AbstractFactory Pattern(C++实现)/*Product.h*/#ifndef PRODUCT_H#define PRODUCT_Hclass AbstractProductA{public: virtual ~AbstractProductA();protected: AbstractProductA();private:};class Abst原创 2015-05-02 20:53:27 · 816 阅读 · 0 评论 -
Factory Pattern(工厂模式)
/*Product.h*/#ifndef PRODUCT_H#define PRODUCT_Hclass Product{public: virtual ~Product()=0;protected: Product();private:};class ConcreteProduct:public Product{public: ~ConcreteProdu原创 2015-05-11 15:43:06 · 524 阅读 · 0 评论 -
Bridge Pattern(桥接模式)
/*Abstraction.h*/#ifndef ABSTRACTION_H#define ABSTRACTION_Hclass AbstractionImp;class Abstraction{public: virtual ~Abstraction(); virtual void Operation()=0;protected: Abstraction();原创 2015-05-08 13:01:06 · 1060 阅读 · 0 评论 -
Builder Pattern(建造者模式)
/*Product.h*/#ifndef PRODUCT_H#define PRODUCT_Hclass Product{public: Product(); ~Product(); void ProducePart();protected:private:};class ProductPart(){public: ProductPart();原创 2015-05-06 11:24:41 · 904 阅读 · 1 评论 -
Decorator Pattern(装饰模式)
/*Decorator.h*/#ifndef DECORATOR#define DECORATORclass Component{public: virtual ~Component(); virtual void Operation();protected: Component();private:};class ConcreteComponent:publi原创 2015-05-11 15:32:43 · 699 阅读 · 0 评论 -
贪吃蛇核心C代码
#include #include #include #include #define SIZEMAX 100 // 定义蛇的最大长度#define SNAKELEN 10 // 蛇的大小和蛇每次移动的距离#define SPEED 100 // 初始速度 /****************************************/typedef enum /...原创 2013-11-02 10:54:46 · 1266 阅读 · 0 评论