zoukankan      html  css  js  c++  java
  • linux下libphenom的测试代码

    使用说明:测试使用libphenom库的字符串追加函数,效率是strcat的60多倍。所以在进行大量的字符串累加的时候可以考虑使用libphenom库

     依赖库:

    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
    ", text->buf);
        printf ("text len:%d
    ", 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()这个函数
    //遇到的话就会中断,使有的字符串追加不完整
    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

     

  • 相关阅读:
    Java内存区域
    spring学习之Bean
    记一次日本公司的Java面试
    java中打印输出数组内容的三种方式
    Java创建子类时构造器执行顺序
    转发&重定向
    Java继承
    GXOI&GZOI
    LCT能干啥???
    后缀自动机的一些应用
  • 原文地址:https://www.cnblogs.com/etangyushan/p/4888071.html
Copyright © 2011-2022 走看看