自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(63)
  • 资源 (2)
  • 收藏
  • 关注

原创 vsnprintf长度

由于vsnprintf需要预先分派长度,所以并不能准确判断到底需要多长,这里通过首次分派1024来判断,若不够,后续继续分派,可得到格式化后的buffer和长度//Handle buffer length of vsnprintf#include #include #include #include typedef std::tr1::shared_ptr Stri

2015-10-30 14:33:26 2478

原创 TCP校验和算法

关于二进制反码求和,并非完全校验。也就是说假如只有一个字节有变,那么校验和一定能正确校验,但如果多个字节变动,而且变动的字节之和等于未变动的和,则将会被当作校验成功。uint16_t checksum(uint16_t *buffer, int size){    unsigned long cksum = 0;    while (size > 1)    {

2015-10-30 14:23:05 1355

原创 判断字符串是否UTF8, 支持最大6个字节的UTF8字符

#include #include #ifndef FALSEtypedef int8_t BOOL;#define TRUE 1#define FALSE 0#endiftypedef struct _UTF8_HEAD{    uint8_t countOf1;    uint8_t head;}UTF8_HEAD;const sta

2015-09-01 11:10:59 2060

原创 C++ virtual table pointer - vptr

To implement virtual functions, C++ uses a special form of late binding known as the virtual table. The virtual table is a lookup table of functions used to resolve function calls in a dynamic/late bi

2015-02-13 20:08:47 1159

原创 C++ const

1. By Default, const Objects Are Local to a File默认情况下,const对象是本地的这是《C++ primary 5th》里的原文When a const object is initialized from a compile-time constant, such as in ourdefinition of bufSize

2015-02-13 15:46:59 731

原创 C++笔记

#constconst对象只能访问const成员函数,而非const对象可以访问任意的成员函数,包括const成员函数.#abstract classThere is no virtual table on it

2015-02-12 18:12:27 699

转载 二叉树的建立、销毁、各种遍历(递归、非递归)

出自 http://blog.csdn.net/luxiaoxun/article/details/7536992//二叉树操作class Node{public: char data; Node *left; Node *right; Node():data(' '),left(NULL),right(NULL){} Node(c

2015-02-12 16:48:06 759

原创 选择排序和快速排序性能比较

这里为了不修改我之前的文章,重新贴一下之前的代码#if 01//selectSort && quickSort comparison#include #include #include #include #include #include #include void swap(int *a, int *b){ int temp = *a;

2015-02-11 19:39:29 1071

原创 Linux栈空间及栈地址方向

写了个简单程序,可以让linux的栈空间耗尽,然后出现core dumped,即栈溢出代码如下:#include void overFlow(){    long i;    printf("&i  : %p\n",&i);    overFlow();}int main(){   OverFlow();}

2015-02-10 18:21:20 5018

原创 Member function callback

#include #include class Core;class Thread{public:    Thread();    virtual ~Thread();protected:    virtual void run() = 0;private:    static void* threadWrapper(void* me);

2014-11-18 14:50:16 738

翻译 Why is the size of an empty class not zero in C++?

Why is the size of an empty class not zero in C++?Predict the output of following program? #includeusing namespace std;class Empty {};int main(){ cout << sizeof(Empty); return 0;}

2014-11-17 11:21:41 830

原创 Ubuntu 12.04安装基于fcitx的sogou输入法,可用

如果你的fcitx不能使用,或者出现“搜狗面板程序加载失败,请重启以使用输入法”,都请先卸载fcitx。卸载方法可以使用sudo apt-get autoremove fcitx,或者直接在software center搜索fcitx并卸载。我的电脑环境:1. System version - Ubuntu 12.04.*;2. Connected to internet.

2014-08-24 18:04:27 6636

原创 一个格式较好的log4cplus properties配置文件

log4cplus.appender.ALL_MSGS=log4cplus::RollingFileAppenderlog4cplus.appender.ALL_MSGS.MaxFileSize=100MBlog4cplus.appender.ALL_MSGS.MaxBackupIndex=10log4cplus.appender.ALL_MSGS.File=./log/thunder

2013-09-22 22:16:19 5464

原创 公共的makefile, C/C++

makefile.mkCC=$(CXX)#ifndef NAME#    NAME=$(notdir $(TARGET_DIR))#endifTARGET=$(TARGET_DIR)/$(NAME)CXXFLAGS = $(INC) $(LIB)ifdef DEBUG    OBJ_DIR=.debug    CFLAGS+= -

2013-08-28 23:26:47 771

原创 将博客搬至CSDN

nothing

2013-07-10 22:08:44 687

原创 我的博客今天1岁352天了,我领取了…

我的博客今天1岁352天了,我领取了徽章.  2011.04.10,我在新浪博客安家。2011.04.10,我写下了第一篇博文:《初》。至今,我的博客共获得6,836次访问。这些年,新浪博客伴我点点滴滴谱写生活!

2013-07-10 22:08:42 537

原创 System&nbsp;V&nbsp;信号量操作,进程间通信(…

//实现semWait, semPost封装#include #include #include #include #include #include #include #include union semun {    int val;                    struct semid_ds *buf;         ushort *a

2013-07-10 22:08:40 707

原创 System&nbsp;V&nbsp;信号量操作,进程间通信(…

首先说明下System Vsemaphore和Posix semaphore的区别 二者是信号量的两组程序设计接口函数。POSIX semaphore来源于POSIX技术规范的实时扩展方案(POSIX Realtime Extension),常用于线程;System V semaphore,常用于进程的同步。这两者非常相近,但它们使用的函数调用各不相同。前一种的头文件为semapho

2013-07-10 22:08:37 676

原创 epoll监听pipe,fork后父进程写给…

这里日志算是一个独立的部分,大可不看,主要是用来记录信息而已,读者可直接用标准输出替换首先,创建pipe,创建子进程,将pipefd[0](read)加入epoll事件,fork创建父进程,调用write()写入管道,epoll_wait此时便返回结果#include #include #include #include #include #include #include

2013-07-10 22:08:35 2679

原创 数据机构快速排序之c语言实现

#if 01//selectSort && quickSortcomparison#include #include #include #include void swap(int *a, int *b){       int temp = *a;       *a = *b;       *b = temp;}int partition(int a[],

2013-07-10 22:08:33 741

原创 系统信号表格和一些资料

值名 字说         明01SIGHUP挂起(hangup)当终端机察觉到终止连线操作时便会传送这个信号02SIGINT中断,当用户从键盘按^c键或^break键时,则会产生此信号03SIGQUIT退出,当用户从键盘按quit键时,如CTRL+\,则会产生此信号04SIGILL非法指令(进

2013-07-10 22:08:31 893

原创 linux下mysql扩展,自定义函数实现(…

Adding a New User-DefinedFunction"The MySQL source distribution includes a filesql/udf_example.c that defines 5 new functions"下载mysql在目录中可看到sql/udf_example.c,我们可以参考。流程:编译自己的动态库=>创建函数首先建立一个简单的测试函

2013-07-10 22:08:29 1162

原创 使用事件驱动模型实现高效稳定的网…

作者顾 锋磊, 软件工程师,IBM简介: 围绕如何构建一个高效稳定的网络服务器程序,本文从一个最简单的服务器模型开始,依次介绍了使用多线程的服务器模型、使用非阻塞接口的服务器模型、利用select()接口实现的基于事件驱动的服务器模型,和使用libev事件驱动库的服务器模型。通过比较各个模型,得出事件驱动模型更适合构建高效稳定的网络服务器程序的结论。前言事件驱动为广大的程序员所熟悉,

2013-07-10 22:08:27 803

原创 简单socket服务器客户端

#include #include #include #include #include #include #include #include #include #define SERVPORT 8088#define SERVER#ifdef SERVERint main(void) {int sockfd, client_sockfd;struct sock

2013-07-10 22:08:24 608

原创 Beej&#039;s&nbsp;Quick&nbsp;Guide&nbsp;to&nbsp;GDB

Beej'sQuick Guide to GDBRelease 2 (2009 Jun 14)This is a very quick-and-dirty guide meant to get you startedwith the GNU Debugger, gdb, from the command line in a terminal.Often times gdb is run

2013-07-10 22:08:22 1339

原创 文件锁File&nbsp;Locking示例

#include #include #include #include #include #define TEST_FILE "00000.txt"int main(int argc, char *argv[]){ // if F_WRLCK,then will blocked with bothread and read suspending // if F_RDLCK,

2013-07-10 22:08:20 840

原创 内存映射文件mmap&nbsp;demo

#include #include #include #include #include #include #include #include #define TEST_FILE "00000.txt"int main(int argc, char *argv[]){int fd, offset;char *data;struct stat sbuf;if (arg

2013-07-10 22:08:18 1046

原创 Semaphores

Remember filelocking? Well, semaphores can be thought of as really genericadvisory locking mechanisms. You can use them to control access tofiles, sharedmemory, and, well, just about anything you

2013-07-10 22:08:16 900

原创 daemon

Unix Daemon ServerProgrammingIntroductionUnix processes works either in foreground or background. Aprocess running in foreground interacts with the user in front ofthe terminal (makes I/O), where

2013-07-10 22:08:13 818

原创 计算机程序数据存储&nbsp;堆&nbsp;栈

堆和栈的区别一、预备知识—程序的内存分配  一个由C/C++编译的程序占用的内存分为以下几个部分  1、栈区(stack)— 由编译器自动分配释放,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈。  2、堆区(heap) — 一般由程序员分配释放, 若程序员不释放,程序结束时可能由OS回收。注意它与数据结构中的堆是两回事,分配方式倒是类似于链表。  3、全局区(静态

2013-07-10 22:08:06 648

原创 守护进程

守护进程简介  守护进程,也就是通常说的Daemon进程,是Linux中的后台服务进程。它是一个生存期较长的进程,通常独立于控制终端并且周期性地执行某种任务或等待处理某些发生的事件。守护进程常常在系统引导装入时启动,在系统关闭时终止。Linux系统有很多守护进程,大多数服务都是通过守护进程实现的,同时,守护进程还能完成许多系统任务,例如,作业规划进程crond、打印进程lqd等(这里的结尾字母d

2013-07-10 22:08:04 503

原创 Linux哈希表使用的简单程序

#include #define DATA_SIZE 256typedef struct _MY_HASH_NODE_{long unsigned lHashValue;char psValue[256];int nCount;}MyHashNode;unsigned long MyHash(const MyHashNode *ptNode){    returnptNod

2013-07-10 22:08:02 1137

原创 yacc死循环问题原因

今天yacc死循环,太不让人活了,原因:自定义输入串需要修饰,结束需将返回值置零,自定义输入函数可如下int my_input(char *psBuffer, int nMaxSize){       static int in=0;       if(in!=0)              return 0;       int n = strlen(g_psMyInput

2013-07-10 22:08:00 687

原创 Redis安装与主从配置

Redis是一种高级key-value数据库。它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富。有字符串,链表,集合和有序集合。支持在服务器端计算集合的并,交和补集(difference)等,还支持多种排序功能。所以Redis也可以被看成是一个数据结构服务器。Redis的所有数据都是保存在内存中,然后不定期的通过异步方式保存到磁盘上(这称为“半持久化模式”);也可以

2013-07-10 22:07:58 834

原创 vim个人总结

命令模式下:set nu->查看行号;noh->no highlight;?->逆向查找;/正向查找#vim html.txtvim search function: ? used to search up the current postion,/ used to search down the current postion; shift+n,the specify thene

2013-07-10 22:07:56 558

原创 MIME&nbsp;编码方式简介

MIME 编码方式简介 MIME 编码方式简介Subject:=?gb2312?B?xOO6w6Oh?=这里是邮件的主题,可是因为编码了,我们看不出是什么内容,其原来的文本是:“你好”Subject: =?gb2312?B?xOO6w6Oh?=这里是邮件的主题,可是因为编码了,我们看不出是什么内容,其原来的文本是:“你好!”我们先看看 MIME 编码的两种方法。对邮件进行编码

2013-07-10 22:07:54 933

原创 php实现的下载附件,解决乱码

通过把Content-Type设置为application/octet-stream,可以把动态生成的内容当作文件来下载,相信这个大家都会。 那么用Content-Disposition设置下载的文件名,这个也有不少人知道吧。 基本上,下载程序都是这么写的:$filename = "document.txt";header('Content-Type: application/oct

2013-07-10 22:07:51 928

原创 linux下SVN安装配置,eclipse提交…

今天安装了下linux下的SVN服务器,网上方法很麻烦,都不想看,我就自己本地作为服务器,实现我自己的版本管理,自己琢磨着怎么去使用  网上提到安装SVN服务器需要安装其他的东西,我用rpm -aq|grep查看,原来我系统自带,如$rpm -aq|grep apr  $rpm -qa |grepneon   由于apache我安装过,现在需要安装SVN服务器,我喜欢跑到应用

2013-07-10 22:07:49 1248

原创 GDB&nbsp;查看循环体内变量的值

98 int foo(){ 99 100        int i,j;101        int sum;102        while(++i 103        {104               sum = i + j;105               ++j;106        }107        return sum;108 }

2013-07-10 22:07:47 951

原创 GDB调试学习(七)

改变程序的执行———————   一旦使用GDB挂上被调试程序,当程序运行起来后,你可以根据自己的调试思路来动态地在GDB中更改当前被调试程序的运行线路或是其变量的值,这个强大的功能能够让你更好的调试你的程序,比如,你可以在程序的一次运行中走遍程序的所有分支。      一、修改变量值   修改被调试程序运行时的变量值,在GDB中很容易实现,使用GDB的print命令即可完成。

2013-07-10 22:07:45 535

贷款计算源码

根据个人输入,可以输出总利息、月供、每期所还利息、每期剩余本金等信息。输入参数分别为 贷款总额 贷款利率 [贷款期数],贷款期数可不输入,默认为240期,即20年。

2014-12-01

android官方下载的repo

由于android官网无法直接访问,难以获得官方的repo脚本。这里提供一个官方下载的repo供大家下载研究

2014-09-06

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除