linux下libphenom的测试代码
2015-10-17 19:52
621 查看
[b]使用说明:测试使用libphenom库的字符串追加函数,[/b]效率是strcat的60多倍。所以在进行大量的字符串累加的时候可以考虑使用libphenom库
依赖库:
安装步骤:
头文件:
编译选项 -lphenom -ltap:
测试代码:
libphenommain.c源码:
libphenomtest.c源码:
说明:如果其他.c文件调用libphenom只要在主函数中初始化就可以,使用时在.c文件中加入
编译链接:
依赖库:
ck-0.4.5.tar.gz cmake-3.1.2.tar.gz libtap-1.12.0.tar.bz2 libphenom.tar.gz
安装步骤:
tar zxf ck-0.4.5.tar.gz ./configure make make install cp /usr/local/lib/pkgconfig/ck.pc /usr/lib64/pkgconfig/ vim /etc/ld.so.conf /usr/local/lib/ tar zxf libphenom.tar.gz ./autogen.sh ./configure make make check sudo make install tar zxf cmake-3.1.2.tar.gz ./configure make make install tar jxf libtap-1.12.0.tar.bz2 mkdir build cd build cmake .. make make check make install
头文件:
#include <phenom/sysutil.h> #include <phenom/string.h> #include <phenom/stream.h>
编译选项 -lphenom -ltap:
例如:gcc libphenommain.c libphenomtest.c -lphenom -ltap
测试代码:
使用libphenommain.c和libphenomtest.c两个源码文件说明使用方法
libphenommain.c源码:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <phenom/sysutil.h> #include <phenom/string.h> #include <phenom/stream.h>
ph_memtype_def_t mt_def = { "test", "misc", 0, 0 };
ph_memtype_t mt_misc = 0;
int main ()
{
int bufsize = 0;
//初始化libphenom
ph_library_init();
mt_misc = ph_memtype_register (&mt_def);
ph_string_t *text;
text = ph_string_make_empty (mt_misc, 16);
//追加字符串
test (text);
printf ("text content:%s\n", text->buf);
printf ("text len:%d\n", text->len);
//释放
ph_string_delref(text);
return 0;
}
libphenomtest.c源码:
#include <stdio.h>
#include <stdlib.h>
#include <phenom/sysutil.h> #include <phenom/string.h> #include <phenom/stream.h>
extern ph_memtype_def_t mt_def; extern ph_memtype_t mt_misc;
int test (ph_string_t *text)
{
//字符串追加测试
int bufsize = 0;
char *buf = "hahah";
//ph_string_append_cstr(text, buf);
//注意这里使用的是ph_string_append_buf()这个函数,因为ph_string_append_cstr()这个函数
//遇到\0的话就会中断,使有\0的字符串追加不完整
bufsize = strlen(buf);
ph_string_append_buf (text, buf, bufsize);
char *buf2 = "hahah2";
//ph_string_append_cstr(text, buf2);
bufsize = strlen(buf2);
ph_string_append_buf (text, buf2, bufsize);
return 0;
}
说明:如果其他.c文件调用libphenom只要在主函数中初始化就可以,使用时在.c文件中加入
extern ph_memtype_def_t mt_def; extern ph_memtype_t mt_misc;
编译链接:
gcc libphenommain.c libphenomtest.c -lphenom -ltap
相关文章推荐
- 对centos6下时间同步(ntp)操作的讨论
- linux 读书笔记2
- centos7通过firewalld更改sshd端口
- linux读书笔记1
- 利用Linux系统函数实现线程池(C++)
- Linux C 时间相关
- Linux-CentOS 编译PHP扩展库.so
- linux下如何拷贝文件到U盘
- LINUX 环境下源码方式安装mysql(二)my.cnf配置细节详解
- 在CentOS上搭建PHP服务器环境
- CentOS 7.0安装Nvidia驱动
- linux---finger命令
- CentOS下安装openoffice和Swf
- linux下c语言递归实现ls -l功能
- 学习日志---linux磁盘格式化
- linux环境变量设置详解
- zookeeper安装与配置(Linux)
- 基于linux2.6.35的串口平台驱动探索
- Linux运维的必备技能【我的技术我做主】
- Linux64位程序移植