
c/c++
kobe8tracy
这个作者很懒,什么都没留下…
展开
-
内存对齐
看书看到内存对齐一段时,突然想研究一下内存对齐最底层的原理.查找资料后总结如下.先用一句话来概括:“[color=darkred][b]数据项只能存储在地址是数据项大小的整数倍的内存位置上[/b][/color]” 例如int是4个字节,则只能在地址是0,4,8等位置上(即最后字节可以整除4).不同的系统有不同的对齐系数(一般32位系统是4字节(正好是32位数据线宽度),64位...原创 2013-03-28 14:27:14 · 88 阅读 · 0 评论 -
C++ 一些小点
一些小的点,防止忘了再查资料1.类的所有对象共享虚函数表。只不过每个对象保存一份虚函数表地址的指针2.非虚函数在编译期就静态绑定了。原创 2014-01-14 15:29:33 · 112 阅读 · 0 评论 -
创建动态链接是链接静态库报错
创建一个动态库时报错,如下relocation R_X86_64_32 against `vtable for Base' can not be used when making a shared object; recompile with -fPIC../sdk/lib/libbase.a: could not read symbols: Bad value因为其中链接了一个静...原创 2014-01-03 14:06:07 · 301 阅读 · 0 评论 -
nginx hash源码分析
HASH是NGINX核心数据结构之一.见几个链接.分析的很详细1.http://www.linuxidc.com/Linux/2012-08/67040.htm2.http://www.oschina.net/question/234345_420653.http://blog.youkuaiyun.com/lifeibo/article/details/58971264.http://cod...原创 2013-02-05 19:05:55 · 148 阅读 · 0 评论 -
c++ 虚函数 const等的一些小问题记录
class Base{public: void test(int a); void test(const int a);//error,不属于重载的范畴,函数名冲突.而且这么定义没意义,本来传值就不会改变原值。}class Base{public: void test(int &a); void test(const int &a);//...原创 2013-11-14 16:14:34 · 539 阅读 · 0 评论 -
c++ protected误区
发现以前对protected的用法一直是错误的。protected的继承的访问权限其实是相对于类的,而不是对象。这么说可能无法理解。看例子:class Base{protected: int a;public: Base();};class Child{public: Child(); test(Child &c){...原创 2013-11-14 15:11:01 · 150 阅读 · 0 评论 -
c++动态陷阱
记录以防忘记class base{public: ........};class derive:public base{public: void test();};intmain(){ derive child; base *father = &child; father->test();//error...原创 2013-11-14 14:35:01 · 94 阅读 · 0 评论 -
c实现bitmap
直接上代码.[code="java"]#include #include #include #define MAX 8972654 //随便设定的数#define SHIFT 5int bitmap[1 + MAX/32];int setbit(unsigned int x);int clearbit(unsigned int x);void print...原创 2013-05-14 14:34:23 · 146 阅读 · 0 评论 -
fgetc read缓冲机制区别
read属于系统调用,它的缓存是基于内核的缓冲,是记在内核空间的.而fgetc是标准函数, 是在用户空间I/O缓冲区的比如用fgetc读一个字节,fgetc有可能从内核中预读1024个字节到I/O缓冲区中,再返回第一个字节,这时该文件在内核中记录的读写位置是1024,而在FILE结构体中记录的读写位置是1.所以如果read一次读取的缓冲大小是1个字节,则1K的文件,read需要...2012-11-13 22:02:08 · 178 阅读 · 0 评论 -
c 指针陷阱
void test(char ***s, int x, int y){ printf("%p\n", s); printf("%p\n", s + 1); printf("%p\n", (char *s) + 1);}如果s的地址是0xbfe83210,则s + 1的地址是0xbfe83214, (char *s) + 1的地址是0xbfe83211....原创 2013-10-08 20:00:50 · 161 阅读 · 0 评论