随笔分类 -  C++

stl mmap实现
摘要:使用mmap函数实现allocator 内存管理 阅读全文

posted @ 2016-03-22 17:53 kangbry

判断是否数组
摘要:template bool isArray(T) { return false; } template bool isArray(T[]) { return true; } int main() { int a[] = {1,2}; int b = 0; cout<<isArray(a)<<endl; cout<<isArray(b)<<endl; return 0; } ... 阅读全文

posted @ 2016-01-14 16:09 kangbry

位域
摘要:~ 阅读全文

posted @ 2015-03-25 23:33 kangbry

fork函数
摘要:#include #include int main () { pid_t fpid; //fpid表示fork函数返回的值 int count=0; fpid=fork(); if (fpid < 0) printf("error in fork!"); else if (fpid =... 阅读全文

posted @ 2015-03-18 23:37 kangbry

ptrace学习
摘要:x64 ptrace使用#include #include #include #include #include #include #include #include int main(){ pid_t child; long orig_eax; child = fork(); ... 阅读全文

posted @ 2014-12-08 13:16 kangbry

http
摘要:~ 阅读全文

posted @ 2014-11-24 20:49 kangbry

死锁
摘要:产生死锁的原因主要是: 1)因为系统资源不足。 2)进程运行推进的顺序不合适。 3)资源分配不当等。如果系统资源充足,进程的资源请求都能够得到满足,死锁出现的可能性就很低,否则就会因争夺有限的资源而陷入死锁。其次,进程运行推进顺序与速度不同,也可能产生死锁。产生死锁的四个必要条件: 1)互斥条件:一... 阅读全文

posted @ 2014-11-24 14:09 kangbry

inline函数
摘要:在C&C++中一、inline关键字用来定义一个类的内联函数,引入它的主要原因是用它替代C中表达式形式的宏定义。表达式形式的宏定义一例:#define ExpressionName(Var1,Var2) ((Var1)+(Var2))*((Var1)-(Var2))取代这种形式的原因如下:1. C中... 阅读全文

posted @ 2014-11-20 23:45 kangbry

linux动静态库使用
摘要:#include#include "cac.h"int main(void){ printf("add = %d\n" ,add(5,3)); printf("sub = %d\n" ,sub(5,3)); return 0;}int add(int a,int b){ re... 阅读全文

posted @ 2014-11-18 22:29 kangbry

中文字符
摘要:#include#include #include using namespace std;void char2Hex(char c) // 将字符以16进制表示{ char ch = ((c&0xF0)>>4)+'0'; // char ch = c/0x10 + '0'; // 汉字占两位 ... 阅读全文

posted @ 2014-11-13 21:18 kangbry

动态库函数
摘要:linux调用库的方式有三种:1.静态链接库2.动态链接库(隐式)3.动态加载库(显式)其中1,2都是在编程时直接调用,在链接时加参数-l进行链接第三种需要在编程时使用dlopen等函数来获取库里面函数的定义,然后进行调linux readlinkdlopen 加载动态库dlclose 卸载的动态库... 阅读全文

posted @ 2014-10-31 16:17 kangbry

100步问题
摘要:回溯问题,可以递归解决,不断试探走一步,走两步 void go(int n,int step,int& sum) { n = n - step; if(n > 0) { go(n,1,sum); go(n,2,sum); } else if(n==0) { sum ++; } } int main( 阅读全文

posted @ 2014-10-28 21:46 kangbry

udp编程
摘要:int sendto (int s, const void *buf, int len, unsigned int flags, const struct sockaddr *to, int tolen); int recvfrom(int s, void *buf, int len, unsign... 阅读全文

posted @ 2014-10-26 21:41 kangbry

常用算法
摘要:二分查找int binary_search(int a[],int len,int goal){ int beg = 0; int end = len - 1; while(beg goal) end = middle - 1; else ... 阅读全文

posted @ 2014-10-26 18:02 kangbry

字符串算法
摘要:字符串逆转void reverse(char* str,int beg,int end){ int times = (end- beg +1)/2; while(times > 0) { char tmp = str[end]; str[end--] =... 阅读全文

posted @ 2014-10-26 16:31 kangbry

左值右值
摘要:C/C++语言中可以放在赋值符号左边的变量,左值表示存储在计算机内存的对象,左值相当于地址值。右值:当一个符号或者常量放在操作符右边的时候,计算机就读取他们的“右值”,也就是其代表的真实值,右值相当于数据值 阅读全文

posted @ 2014-10-25 14:51 kangbry

异常处理
摘要:1) 异常的抛出和处理主要使用了以下三个关键字:try, throw, catch 2) 抛出异常即检测是否产生异常,在C++中,其采用throw语句来实现,如果检测到产生异常,则抛出异常。该语句的格式为:throw 表达式;3) 在try语句块的程序段中(包括在其中调用的函数)发现了异常,且抛弃了... 阅读全文

posted @ 2014-10-25 13:52 kangbry

extern inline volatile explicit
摘要:1. extern是一个关键字,它告诉编译器存在着一个变量或者一个函数,如果在当前编译语句的前面中没有找到相应的变量或者函数,也会在当前文件的后面或者其它文件中定义2. 调用extern "C"关键字,声明cpp文件中有关代码,需要按照C的方式来生成1. 在函数声明或定义中函数返回类型前加上关键字i... 阅读全文

posted @ 2014-10-25 13:05 kangbry

const
摘要:const作用 1) 可以定义const常量 const int max = 1002) 对传入的参数进行类型检查,不匹配进行提示 void f(const int i) { .........}3) 可以保护被修饰的东西 void f(const int i) { i=10;//error! }4... 阅读全文

posted @ 2014-10-24 22:29 kangbry

序列化tinybuf
摘要:/* ------------------------------------------------------------------------------- | 数据头标记(1字节) | ID标识字段(不一定有) | ------------------------------------... 阅读全文

posted @ 2014-10-24 09:18 kangbry

导航