03 2016 档案
摘要:main1.c#include #include #define MY_FIFO "/tmp/myfifo"int main(void){ int ret; ret = mkfifo(MY_FIFO, 0777); if (ret == -1) { ...
阅读全文
摘要:管道的缺点 管道只能在具有“亲戚”关系的进程之间通信。 即仅当管道由某个进程创建之后,在该进程的所有子孙进程之间,可通过该管道来通信。其他情况下的无此“亲戚”关系的进程不能使用管道通信。解决办法:使用命名管道什么是命名管道? 命名管道是一种特殊的文件, 命名管道以普通文件的形式(在...
阅读全文
摘要:main1.c#include #include #include int main(void) { int fd[2]; int ret; char buff1[1024]; char buff2[1024]; ret = pipe(fd); ...
阅读全文
摘要:管道 1 使用信号进行通信 进程之间使用“信号”进行通信的优缺点 优点:简单 缺点:传递的信息有限, 只能传递一个简单的“信号值”解决方案: 使用“管道”进行进程间通信。注: 进程间通信,简称“IPC” 2 什么是管道 IPC 有多种方式, 管道是IPC的最基本的方式....
阅读全文
摘要:main1.c#include #include int main(void){ while(1) { printf("work...\n"); sleep(3); } return 0;}main2.c#include #includ...
阅读全文
摘要:创建两个子进程; 子进程1对文件mytest.txt进行写操作, 每5秒写入一次, 写入当时的时间。 子进程2对文件mytest.txt进行读操作, 每5秒中读一次, 读取并打印文件中所写入的最新时间。...
阅读全文
摘要:main1.c#include #include int main(void){ char *buff; void *buff2; buff = malloc(1024); // ∏≥÷µ ±Ω¯––¡À¿‡–Õ◊™ªª ...
阅读全文
摘要:内存管理什么是内存?内存是一种稀缺资源。Linux程序不允许直接访问物理内存,都通过虚拟内存的方式访问。 物理地址 虚拟地址Linux通过内核的”存储管理”,给用户提供了”虚拟内存”。 虚拟内存可以比实际的物理内存大。内存分配 1)简单的内存分配 使用malloc 以字节为单位...
阅读全文
摘要:main.7#include #include int main(void){ system("ls -l"); printf("end!\n"); return 0;}main8.c#include #include #include int main(void...
阅读全文
摘要:什么是进程程序的运行实例,就是“进程” 一个程序,同时执行多次,则产生多个不同的进程。程序是静态的 进程是动态的进程的结构 进程的组成:程序代码、数据、变量、文件描述符(表示已打开的文件)、环境等组成。每个进程有一个唯一的编号,称为”进程标识符”(PID) PID >= 2 PID...
阅读全文
摘要:main1.c#include #include int main(void){ int i; char buff[] = "hello world\n"; write(1, buff, sizeof(buff)); write(2, buff, sizeo...
阅读全文
摘要:文件的作用 linux中,一切皆文件(网络设备除外) 硬件设备也“是”文件,通过文件来使用设备 目录(文件夹)也是一种文件Linux的文件结构 了解各主要文件夹的作用系统调用和设备驱动程序之间的关系 应用层的open, close, read, write, ioctl与驱动程序的...
阅读全文
摘要:01_类模板的定义.cpp#include#includeusing namespace std;templateclass A{ public: T t; A(){} A(const T &rt){ t = rt;} ~A(){}};int main...
阅读全文
摘要:01_函数模板定义.cpp#include#include using namespace std;#if 0int MAX(int a,int b){ coutb?a:b;}char MAX(char a,char b){ coutb?a:b;}double MAX...
阅读全文
摘要:01_多继承定义.cpp#includeusing namespace std;//父类先构造,子类先析构struct GrandFather{ int pound=2000000; GrandFather(){ coutusing namespace s...
阅读全文
摘要:01_单继承语法.cpp#includeusing namespace std;//继承就是使得一个类可以拥有另一个类的成员数据和方法的一种快速语法形式//语法://class/struct [子类名]:[父类名]// [派生类]:[基类]struct Fa...
阅读全文
摘要:1C++_类成员变量指针.cpp#includeusing namespace std;struct A{ int m=10; int n=9;};//类的成员变量指针,只能指向该类的成员变量,不会超出范围,这样做可以减小程序员纠错的范围,提高代码的维护性int mai...
阅读全文
摘要:1c++_union.cpp#includeusing namespace std;//union是联合体,其所在空间是其内部最大元素的空间大小 ,换句话说,其内部所有成员的空间是共用的union A{ int a=0x30313233; char s[4];};int...
阅读全文
摘要:1_枚举类.cpp#include//枚举类是带有类类型特征的枚举类型using namespace std;enum class COLOR {RED,BLUE,GREEN}; //default: RED=0; BLUE=RED+1;...class Book_b...
阅读全文
摘要:1 constexpr类.cpp#includeusing namespace std;//constexpr 类是指该类的构造函数被constexpr修饰后,其传递的参数不能是变量,只能是常量(只读变量,字面值)class A{ int a,b; public: ...
阅读全文
摘要:1_聚合类.cpp#includeusing namespace std;//如果一个类只定义成员变量,而没有定义成员函数,那么该类被称作聚合类struct student{ int id; string name; int age;};int main(){} ...
阅读全文
摘要:01_局部类.cpp#includeusing namespace std;//局部类是指在一个函数内部定义的类int get(){ int m=100; class A{ public: A(){/*cout<<m<<endl;*/} ...
阅读全文
摘要:01_内部类.cpp#includeusing namespace std;//内部类是指在一个类内部定义的类//内部类本质就一个类,但是因其它在另一个类内部定义的,所以它可以访问外部类的成员class A{ class Inner{ public: ...
阅读全文
摘要:1移动赋值运算符.cpp#include#includeusing namespace std;class my_string{ char* p=nullptr; public: my_string(){} my_string(const char* s){...
阅读全文
摘要:1 c++ 移动构造函数.cpp#include#includeusing namespace std;class my_string{ char* p=nullptr; public: my_string(){} my_string(const char*...
阅读全文
摘要:#includeusing namespace std;int main(){ //左值: int a=10; int b=9; //右值: /* a+b,add(a,b),1000,'a',"123"; */ //左值引用...
阅读全文
摘要:#includeusing namespace std;class auto_pint{ class node{ public: int ref_count=0; int number=0; }; node * p =nu...
阅读全文
摘要:01_lambda表达式.cpp#include#includeusing namespace std;class Func_call{ public:// Func_call(){coutbool 尾置返回类型 //{} 执行体 ...
阅读全文
摘要:01_重载函数调用运算符.cpp#includeusing namespace std;class Func_call{ public: Func_call(){coutb; }};int main(){ Func_call fc /*()*/;//具名对象...
阅读全文
摘要:1重载类型转换运算符.cpp#includeusing namespace std;class A{ public: int m=0; A()=default; A(int k){m=k;} ~A(){} operator int() { ...
阅读全文
摘要:1 C++ 重载解引用_迭代器.cpp#include#includeusing namespace std;//实现迭代器的目的是可以进行泛型计算,比如使用范围for语句等等;//实现迭代器的步骤://1,定义一个内部类iterator//2,重载该内部类的!=, ++, */...
阅读全文
摘要:#include#include#includeusing namespace std;class dynamic_int_array{ int * p=nullptr; int size =0; int capacity=0; public: dyn...
阅读全文
摘要:1 赋值运算符重载.cpp#include#includeusing namespace std;class my_string{ char* p=nullptr; public: my_string(){} my_string(const char* s)...
阅读全文
摘要:1 中括号重载.cpp#include#includeusing namespace std;class my_string{ char* p=nullptr; public: my_string(){} my_string(const char* s){ ...
阅读全文
摘要:1 C++ 重载输出符号.cpp#includeusing namespace std; struct Date{ int year,month,day; Date()=default; Date(int y,int m, int d) :year(...
阅读全文
摘要:1 单目运算#includeusing namespace std;//复数class Complex{ public: double real,image; Complex()=default; Complex(double r, double i) ...
阅读全文
摘要:#includeusing namespace std;int add(int a, int b){ return a+b;}int main(){ string s1 ="abc"; string s2 ="def"; string s3 = s1 + s...
阅读全文
摘要:1成员函数重载#include#includeusing namespace std;class Cycle;class Point{ double x,y; public: Point()=default; Point(double rx ,double ...
阅读全文
摘要:01_point.cpp #include#includeusing namespace std;class Point{ double x,y; public: Point()=default; Point(double rx ,double ry) ...
阅读全文
摘要:01 _static.cpp#includeusing namespace std;struct student{ int id; string name;static string school; student()=default; student(i...
阅读全文
摘要:01_const_class.cpp#includeusing namespace std;struct A{ int m; int n; A(){} A(int a,int b){m=a;n=b;} ~A(){}};int main(){ co...
阅读全文
摘要:1_student_link_list.cpp#includeusing namespace std;struct student{ int id;string name;int age; student()=default; student(int i,stri...
阅读全文
摘要:01_初始化参数列表.cpp#include#include #include using namespace std;struct Student{ int id=1001;//成员变量或对象 char *name=nullptr; int age=20; ...
阅读全文
摘要:01_拷贝构造定义#include#include #include using namespace std;struct Student{ int id=1001;//成员变量或对象 char *name=nullptr; int age=20; int ...
阅读全文
摘要:01_对象和malloc#include#include #include using namespace std;struct book_bag{ int color; int book_sum; book_bag(){ coutid =1001;...
阅读全文
摘要:1析构函数.#include#include #include using namespace std;struct Student{ int id=1001;//成员变量或对象 char *name=nullptr; int age=20; int sco...
阅读全文
摘要:1 C++成员变量初始化#include#include using namespace std;struct Student{ int id=1001; //成员变量或对象 char name[64]="zhangsan"; int age...
阅读全文
摘要:#include#include using namespace std;struct student{ int id; //成员变量或对象 char name[64]; int age; int score; //...};typed...
阅读全文
摘要:#includeusing namespace std;//constexpr 是更严格的定义只读变量,其要求该变量的初始化值必须是字面值常数(在未来版本可能扩展为也可以用其他只读变量初始化)int main(){ const int a =10; const int ...
阅读全文
摘要:#includeusing namespace std;void get(int a){ cout<<__func__<<"int"<<endl;}void get(int *a){ cout<<__func__<<"int*"<<endl;}int main(){ ...
阅读全文
摘要:#includeusing namespace std;int i =0;void init_cpu(){ cout<<++i<<" "<<__func__<<endl;}void init_serial(){ cout<<++i<<" "<<__func__<<end...
阅读全文
摘要:#includeusing namespace std;//typedef int (*PGET)(int);int get(int a){ cout<<__func__<<" "<<a<<endl; return a;}using PGET = int(*)(int)...
阅读全文
摘要:#includeusing namespace std;//函数前面有inline关键字修饰,那么这个函数就叫做内联函数//内联函数可以加速程序执行的时间//内联函数一定是代码量极少的函数,且不要有浮点操作;//内联函数的缺点是增加了代码段的数量,耗费更多的内存//典型的以空间换时...
阅读全文
摘要:#includeusing namespace std;int get(int a=10){ return a;}double get_cycle_area(double r,double pi=3.1415){ return pi*r*r;}double get_cy...
阅读全文
摘要:#includeusing namespace std;//函数重载:指的是有两个或以上的函数名字相同,但是函数参数的类型或个数不同;int MAX(int a,int b){ coutb?a:b;}char MAX(char a,char b){ coutb?a:b;...
阅读全文
摘要:1.#include#includeusing namespace std;int main(){ vector v(5); cout#includeusing namespace std;int main(){ vector v(5); cout::ite...
阅读全文
摘要:#includeusing namespace std;//函数重载:指的是有两个或以上的函数名字相同,但是函数参数的类型或个数不同;//重载的函数一定要精确匹配,即使能编译通过,但对于出现的warning还是要小心int MAX(int a,int b){ coutb?a:...
阅读全文
摘要:#includeusing namespace std;//函数重载:指的是有两个或以上的函数名字相同,但是函数参数的类型或个数不同;int MAX(const int a,const int b){ coutb?a:b;}int MAX(int a,int b){ c...
阅读全文
摘要:include using namespace std; //函数重载:指的是有两个或以上的函数名字相同,但是函数参数的类型或个数不同;int Max (int a , int b){ cout b? a:b;}char Max (char a, char b){ c...
阅读全文
摘要:UI界面类项目: Panoramagl —— 720全景展示 Panorama viewer library for iPhone, iPad and iPod touchMBProgressHUD —— 进度指示 一种优雅的,半透明的进度显示效果。同时还提供了其他附加功能,比如显...
阅读全文
摘要:1 内存共享 内存的获取 int fd = shmget(key_t key ,size_t size , int shmflg); 内存的关联 void* shmat(int shmid ,const void* shmaddr , in...
阅读全文
摘要:IO五种模式 * 阻塞I|O 非阻塞模式 fcntl(fd , F_SETFL , flag |O_NONBLOCK) int select(int nfds,fd_set *readfds ,fd_set* writefds , fd_se...
阅读全文
摘要:epollserver.cpp#include #include #include #include #include #include #include #include #include #include #include using namespace std;void w...
阅读全文
摘要:usemain.cpp#include#include#include#include#include#include#include#include#include#include#include#include#include"message_type.h"#include"s...
阅读全文
摘要:servermain.cpp#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#includ...
阅读全文
摘要:drivermain.cpp#include#include#include#include#include#include#include#include#include#include#include#include#include#include"message_type.h...
阅读全文
摘要:类别(分类) 1. 为什么要使用分类 问题:需要为已经存在的类添加新的功能,但是又不想为此创建子类。 1)比如,如果需要为NSString添加一个功能,创建NSString类的子类将非常麻烦(因为NSString使用了底层的“类簇”) 2)比如,需要为某个...
阅读全文
摘要:1 NSRunLoop的实现机制,及在多线程中如何使用 NSRunLoop是IOS消息机制的处理模式 1.NSRunLoop的主要作用:控制NSRunLoop里面线程的执行和休眠,在有事情做的时候使当前NSRunLoop控制的线程工作,没有事情做让当前NSRunLoop的控...
阅读全文
摘要:1. 代码块 (block)block 类似于c语言的函数指针 但是比函数指针功能更强,是多种高级语言提供的"闭包"2. 代码块的定义代码块的定义和函数指针相似//返回类型为void的block 定义一个block 返回类型不加括号void(^myblock)(NSString*...
阅读全文
摘要:runtime实现的机制: 运行时机制,runtime库里面包含了跟类、成员变量、方法相关的API,比如获取类里面的所有成员变量,为类动态添加成员变量,动态改变类的方法实现,为类动态添加新的方法等 1. runtime,运行时机制,它是一套C语言库 2. 实际上我们编写的所有OC...
阅读全文
摘要:// condition.h#ifndef _CONDITION_H_#define _CONDITION_H_#includetypedef struct condition{ pthread_mutex_t pmutex; pthread_cond_t pcond;...
阅读全文
摘要://在block里再改变 指针的属性 设置为weak的strong//判断string的值是否为NULL 不为NULL执行需要的代码#define WS(weak_self) _weak typeof(self) weak_self = self//block的防止循环引用的问题...
阅读全文

浙公网安备 33010602011771号