一开始运行出错,开启debug以后发现在push自定义对象的时候调试器提示找不到一个叫/XXX/XXXX/XXXX/libcstl-2.3.0/src/cstl_list_private.c</br>
而那个路径正是我进行安装的路径,安装完以后我把安装包给删除掉了,所以它找不到。这样的话,我们在一开始安装的时候就要注意最好先把tar.gz解压出来的文件夹放到特定文件夹,比如/usr/local/下,这样不会在安装完成后被误删,也比较方便查找。</br>
但是再次调试的时候却发现插入操作死在了调用_my_copy()函数那里,里面设置了一个int型临时变量i_temp用来作中间值方便调试,调试过程中发现i_temp成了一个非常小的负值。
但是直接调用_my_copy()是能正确运行的。</br>
鉴于程序呈现出这种尿性,我觉得应该是cstl它自己设计得不够健壮。。。不然实在是说不通程序会死在_my_copy()函数那里。
其实最后我发现copy函数形参里的cpv_source它的地址为0x1,明显就不可能。这个就关系到cstl对list的内部实现了,不想再深入去了解,暂时到此为止。
最后还是照惯例贴个代码:

 /*
* new_test_for_ctsl_selfType.c
*
* Created on: Mar 21, 2014
* Author: nerohwang
*/
#include<stdio.h>
#include<stdlib.h>
#include<cstl/clist.h>
#include<assert.h>
/*Initlizing a user-defined type ,use
* func type_register(1,2,3,4,5) first.
* 1.type: user-defined type
* 2.ufun_init: init function
* 3.bfun_copy: copy function
* 4.bfun_less: less-comparison function
* 5.ufun_destroy: destroy function bool_t type_register(
type,
unary_function_t ufun_init,
binary_function_t bfun_copy,
binary_function_t bfun_less,
unary_function_t ufun_destroy
);
*
*/
typedef struct user_defined_type
{
int i_first;
int i_second;
}myType; static void _my_init(const void* cpv_input,void* pv_output)
{
assert(cpv_input != NULL);
((myType*)cpv_input)->i_first = ;
((myType*)cpv_input)->i_second = ;
*((bool_t*)pv_output) = true;
} static void _my_copy(const void* cpv_dest,const void* cpv_source,void* pv_output)
{
assert(cpv_dest != NULL && cpv_source != NULL);
int i_temp = ((myType*)cpv_source)->i_first;
((myType*)cpv_dest)->i_first = i_temp;
i_temp = ((myType*)cpv_source)->i_second;
((myType*)cpv_dest)->i_second = i_temp;
*((bool_t*)pv_output) = true;
} static void _my_destroy(const void* cpv_input,void* pv_output)
{
assert(cpv_input != NULL);
((myType*)cpv_input)->i_first = ;
((myType*)cpv_input)->i_second = ;
*((bool_t*)pv_output) = true;
} static void _my_less(const void* cpv_first, const void* cpv_second,void* pv_output)
{
assert(cpv_first != NULL && cpv_second != NULL);
*((bool_t*)pv_output) = (((myType*)cpv_first)->i_first < ((myType*)cpv_second)->i_first)?true:false;
} int main(int argc,char* argv[])
{
list_t* pList = create_list(myType);
list_iterator_t i_it;
list_iterator_t my_it;
printf("Before type register:\n");
if(pList == NULL){
printf("Creation of myType failed!\n");
}else{
printf("Creation of myType succeeded!\n");
}
type_register(myType,_my_init,_my_copy,_my_less,_my_destroy); pList = create_list(myType);
printf("After type register:\n");
if(pList != NULL){
printf("Creation of myType succeeded!\n");
}else{
printf("Creation of myType failed!\n");
} //just a simple test.
myType my_first;
my_first.i_first = ;
my_first.i_second = ;
printf("first :one-> %d,sec-> %d\n",my_first.i_first,my_first.i_second); myType my_second; //default myType my_third;
my_third.i_first = ;
my_third.i_second = ; list_t* pList_i = create_list(int);
if(pList_i == NULL){
printf("Creation of int list failed!\n");
}
list_init(pList_i);
list_push_back(pList_i,);
list_push_back(pList_i,);
list_push_back(pList_i,);
printf("Now we have %d int-var in our list\n",list_size(pList_i));
for(i_it = list_begin(pList_i);!iterator_equal(i_it,list_end(pList_i));i_it = iterator_next(i_it))
{
printf("%d\t",*(int*)iterator_get_pointer(i_it));
}
printf("\n"); bool_t b_temp;
_my_copy((void*)&my_second,(void*)&my_first,(void*)&b_temp);
printf("Second :one-> %d,sec-> %d\n",my_second.i_first,my_second.i_second); printf("break point\n");
list_init(pList);
list_push_back(pList,my_second);
my_it = list_begin(pList);
printf("Second myType: one-> %d , sec->%d\n",((myType*)iterator_get_pointer(my_it))->i_first,\
((myType*)iterator_get_pointer(my_it))->i_second); printf("break point\n");
list_push_back(pList,my_first);
list_push_back(pList,my_third);
printf("Now we have %d obj in our list\n",list_size(pList));
return ; }

libcstl中的list没法插入自定义数据的更多相关文章

  1. Effective Objective-C 2.0 — 第10条:在既有类中使用关联对象存放自定义数据

    可以通过“关联对象”机制来把两个对象连起来 定义关联对象时可指定内存管理语义,用以模仿定义属性时所采用的“拥有关系”与“非拥有关系” 只有在其他做法不可行时才应选用关联对象,因为这种做法通常会引入难于 ...

  2. 用mybatis中的insert方法插入数据,返回值为1,但数据库却没有数据

    刚才在写东西的时候,用mybatis中的 <insert id="add" parameterType="cn.entity.Computer"> ...

  3. Microsoft Azure 上的自定义数据和 Cloud-Init

     自定义数据是什么? 客户经常询问如何才能在配置Microsoft Azure 虚拟机时插入脚本或其他元数据.在其他云中,这个概念通常称为用户数据.MicrosoftAzure 中也有一项类似的功 ...

  4. Apex 中插入更新数据的事件执行顺序

    在使用 Apex 代码插入或更新数据的时候,若干事件会被按顺序执行.了解这些顺序可以提高调试程序的效率,也可以避免不必要的错误. 可以参考官方文档. 事件的执行顺序 从数据库中读取要更新的数据记录或初 ...

  5. sql 中的Bulk和C# 中的SqlBulkCopy批量插入数据 ( 回顾 and 粗谈 )

    通常,我们会对于一个文本文件数据导入到数据库中,不多说,上代码. 首先,表结构如下.   其次,在我当前D盘中有个文本文件名为2.txt的文件. 在数据库中,可以这样通过一句代码插入. Bulk in ...

  6. GridView控件中插入自定义删除按钮并弹出确认框

    GridView控件中插入自定义删除按钮,要实现这个功能其实有多种方法,这里先记下我使用的方法,以后再添加其他方法. 一.实现步骤 1.在GridView中添加模板列(TemplateField). ...

  7. SQL Server 2012中快速插入批量数据的示例及疑惑

    SQL Server 2008中SQL应用系列--目录索引 今天在做一个案例演示时,在SQL Server 2012中使用Insert语句插入1万条数据,结果遇到了一个奇怪的现象,现将过程分享出来,以 ...

  8. 在mysql数据库中创建oracle scott用户的四个表及插入初始化数据

    在mysql数据库中创建oracle scott用户的四个表及插入初始化数据 /* 功能:创建 scott 数据库中的 dept 表 */ create table dept( deptno int ...

  9. C#往SQLServer中插入大数据

    以前插入大数据的时候都是一条一条的插入,由于电脑配置不行,有一次17万条数据用了半个小时才插入完成,那个蛋疼啊! 前面听杨中科老师的课,发现一个很好的东西,25万条数据配置好的电脑几秒钟就完成了,那是 ...

随机推荐

  1. HighCharts使用心得(转载)

    转载自:http://www.cnblogs.com/Olive116/p/3777021.html 1.  准备工作------下载HighCharts插件 跟ECharts一样,HighChart ...

  2. nginx提高加载静态文件速度

    1.本来对于静态网页,我们不需要放在应用容器中,原因一时由于应用服务器是用来解析动态网页的,针对静态网页本来就性能不高,而且还会占用应用容器的资源,所以我们专门使用nginx用来解析静态网页.     ...

  3. ThreadLocal分析总结:

    1.ThreadLocal 是什么 它是一个数据结构,像 HashMap,可保存 "key : value" 键值对:ThreadLocal 有一个内部类ThreadLocalMa ...

  4. UVALive 6933 Virus synthesis(回文树)

    Viruses are usually bad for your health. How about ghting them with... other viruses? In this proble ...

  5. 【转】通过ionice和nice降低shell脚本运行的优先级

    对于一些运行时会造成系统满载的脚本, 例如数据库备份, 会影响当时其他服务的响应速度, 可以通过ionice和nice对其IO优先级和CPU优先级进行调整例如降低"/usr/local/bi ...

  6. 5.2 - ToDoList

    一.ToDoList需求 参考链接http://www.todolist.cn/ 1.将用户输入添加至待办项 2.可以对todolist进行分类(待办项和已完成组),用户勾选既将待办项分入已完成组 3 ...

  7. Junit 3.8.1 源码分析(一)

    写在前面:本文基于Junit3.8.1版本,因为这是我第一次进行源码学习,先从简单的源码开始学起 1. 示例代码 1.1 准备工作 下载Junit3.8.1的JAR包 需要下载junit-3.8.1- ...

  8. 常用WebSite Address

    百度 魅族深度学习应用大赛 byr论坛 帖子 https://bbs.byr.cn/#!article/ML_DM/24852?p=1 百度 魅族深度学习应用大赛 官网 http://meizu.ba ...

  9. Hadoop2.7.3+spark2.1.0+hbase0.98分布式集群部署

    运行环境配置(10.79.115.111-114) 1.关闭防火墙与selinux 关闭防火墙: CentOS 7.x默认使用的是firewall作为防火墙. systemctl stop firew ...

  10. memcache服务端与客户端的安装部署

    1)安装memcached前需要先安装libevent [root@aliyun tools]# tar -zxf libevent-1.4.13-stable.tar.gz [root@aliyun ...