2014年1月15日

realloc以后,原有内存被如何处理? 回收? 释放? 不管?

摘要: 如果已分配的存储块后面有空闲的空间,则realloc不会移动数据而只是增加原来存储块的长度,并返回传给它的原存储块的指针。但当前存储块后面没有足够的空闲空间时,realloc会重新分配一存储块,并移动当前存储块的内容到新块,然后返回新块的指针。realloc() changes the size of the memory block pointed to by ptr tosize bytes. The contents will be unchanged to the minimum of the oldand new sizes; newly allocated memory will 阅读全文

posted @ 2014-01-15 14:54 yuanqing 阅读(1514) 评论(0) 推荐(0)

结构体动态数组的定义及操作

摘要: 这两天在写一个linux下的C项目,需要控制一张临时表,这张表由动态结构体数组构成。需要实现动态数组的创建及其操作结构体如下所示:/*创建一个基站的动态数组的结构体*/typedef struct base_array{ int size ; int count ; struct base *data;}base_array;/*创建一个基站的结构体*/typedef struct base{ char id[6] ; int led; int way; struct locomotive *next ;}base;/*创建一个基站的动态数组*/void create_base_table(b 阅读全文

posted @ 2014-01-15 14:27 yuanqing 阅读(2101) 评论(0) 推荐(0)

导航