c语言怎么实现模块化vc,原创:在C语言中大概实现VC++中的CArray部分功能的两种方法...
#ifndef __LISTARRAY_H__
#define __LISTARRAY_H__
#include "rtthread.h"
#include "finsh.h"
//LIST数组
typedef struct _ListArray ListArray;
struct _ListArray
{
void **pListPointArray; //LIST数组指针
int Total; //元素个数
void (*Add)(ListArray *pList, void *pListPoint); //添加
void (*Remove)(ListArray *pList, void *pListPoint); //移除
void (*Delete)(void *pList); //析构
};
//List类的析构函数
static void ListDelete(void *pList)
{
if(((ListArray *)pList)->pListPointArray != RT_NULL) //先释放指针数组
{
rt_free(((ListArray *)pList)->pListPointArray);
}
rt_free(pList); //再释放整个List类
}
//元素增加函数
static void ListAdd(ListArray *pList, void *pListPoint)
{
void **tListPointArray = rt_malloc(sizeof(int *) * (pList->Total + 1)); //申请比原来大一个存储单元的内存
int pListIndex;
for(pListIndex = 0; pListIndex < pList->Total; pListIndex++) //拷贝
{
if(pList->pListPointArray[pListIndex] == pListPoint) //判断,如果有相同的元素存在
{
rt_free(tListPointArray); //释放现申请的内存
return; //返回
}
tListPointArray[pListIndex] = pList->pListPointArray[pListIndex]; //拷贝
}
tListPointArray[pList->Total] = pListPoint; //将添加的元素放到最后一个存储单元中
pList->Total += 1; //总数加1
if(pList->pListPointArray != RT_NULL) rt_free(pList->pListPointArray); //释放原来的内存
pList->pListPointArray = tListPointArray; //将新的句柄替换原句柄
}
//元素移除函数
static void ListRemove(ListArray *pList, void *pListPoint)
{
int pListIndex, tListIndex;
void **tListPointArray;
void **FreePointArray;
void **SavePointArray;
if(pList->Total == 0) return; //总数为0时退出
tListPointArray = rt_malloc(sizeof(int) * (pList->Total - 1)); //申请比原来小一个存储单元的内存
FreePointArray = tListPointArray; //将刚申请的内存空间作为默认的释放空间
SavePointArray = pList->pListPointArray; //将已有的内存空间作为默认的存储空间
for(pListIndex = 0, tListIndex= 0; pListIndex < pList->Total; pListIndex++) //查找移除点
{
if(pList->pListPointArray[pListIndex] == pListPoint) //当前点是移除点
{
FreePointArray = pList->pListPointArray; //改变释放内存指针
SavePointArray = tListPointArray; //改变保留内存指针
continue; //结束本次循环
}
if(tListIndex < (pList->Total -1)) //如果当前点不是移除点,拷贝序号小于总量减1
{
tListPointArray[tListIndex] = pList->pListPointArray[pListIndex]; //拷贝
tListIndex++; //拷贝序号加1
}
}
pList->Total = (SavePointArray == tListPointArray) ? pList->Total - 1 : pList->Total; //根据保留的内存块改变总数的值
if(FreePointArray != RT_NULL) rt_free(FreePointArray); //释放该释放的不用的内存块
pList->pListPointArray = SavePointArray; //保留该保留的
}
//List构造函数
static ListArray *ListCreate(void)
{
ListArray *pList = (ListArray *)rt_malloc(sizeof(ListArray));
pList->Total = 0;
pList->pListPointArray = RT_NULL;
pList->Add = ListAdd;
pList->Remove = ListRemove;
pList->Delete = ListDelete;
return pList;
}
#endif
c语言怎么实现模块化vc,原创:在C语言中大概实现VC++中的CArray部分功能的两种方法...相关推荐
- C语言中的选择法排序怎么,请问高手们 C语言中选择法排序和冒泡法排序的思想,两种方法有何不同,搞不懂,请举例详细说明一下.谢谢。...
满意答案 yl6485 2013.04.01 采纳率:48% 等级:12 已帮助:6958人 不同点:冒泡法是顾名思义就是把小的泡冒到上面,大的泡沉到下面,最值在中间和其他的值交换: 而选择法, ...
- c语言中fact函数怎么调用,C语言程序题: 1、编写一个求n!的函数fact(n),要求fact函数分别用递归和非递归两种方法实现...
点击查看C语言程序题: 1.编写一个求n!的函数fact(n),要求fact函数分别用递归和非递归两种方法实现具体信息 答:int fac(int n) //非递归{int f=1; for(;n;) ...
- c语言怎么改变程序的图标,VC6.0 控制台程序添加图标的两种方法
如何给C控制台程序添加图标说来很惭愧的问题,C语言也算学了很长一阵子,目前还是停留在控制台的水平,今天用着用着突然想给程序换个图标,却找不到在哪设置,又没窗体,在哪弄呢?百度N久,找到如下两种解决方案 ...
- 使用VC连接Access数据库的两种方法
以前的时候用VC写了两种连接Access数据库的方法,为了方便以后查找把这两种方法做一下简单的介绍.Windows平台的数据接口标准有ODBC.OLE DB.ADO和Borland的BDE接口,ODB ...
- linux c语言乘法口诀,shell 脚本实现乘法口诀表的两种方法——shell与C语言
shell 脚本实现乘法口诀表的两种方法--shell与C语言 话不多说直接给出代码(执行c语言时没有gcc编译器会报错的哦!): 1 #!/bin/bash 2 if [ $# -eq 0 ] 3 ...
- linux中复制字符串出错,C语言实现字符串的复制的两种方法
本文将要为您介绍的是C语言实现字符串的复制的两种方法,具体操作方法: 利用数组实现 1 #include 2 #include 3 4 void copy_string(char str1[],cha ...
- PTA—念数字(C语言)两种方法
PTA-念数字(C语言)两种方法 输入一个整数,输出每个数字对应的拼音.当整数为负数时,先输出fu字.十个数字对应的拼音如下: 0: ling 1: yi 2: er 3: san 4: si 5: ...
- C语言无符号双字节乘法,华为OJ机试标题:两个大整数相乘(纯C语言实现两个大整数相乘,两种方法实现大数相乘)...
华为OJ机试题目:两个大整数相乘(纯C语言实现两个大整数相乘,两种方法实现大数相乘) 题目描述: 输出两个不超过100位的大整数的乘积. 输入: 输入两个大整数,如1234567 123 输出: 输出 ...
- MFC多语言实现的两种方法
前不久由于工作需要,用新工具Passolo制作软件的英文版,顺便回顾了一下以前一直用的老方法--动态加载英文资源的DLL.今天有空整理了一下,与大家分享两种方法是如何实现软件多语言的. 方法一:动态加 ...
最新文章
- $portfolio.isotope is not a function
- servlet——请求乱码问题解决
- SAP Spartacus里unit list tree节点collapse all按钮的实现逻辑
- clear在CSS中的妙用
- 如何在 Ubuntu 12.04 Server 中安装图形用户界面
- (C++) CreateThread
- Part 2 —— 迁移到 Go Modules
- 标签中包含input时line-height属性失效的解决办法
- 手把手教你如何加入到github的开源世界!
- dubbogo PMC何鑫铭:没有热爱就做不成这件事情
- 计算机网络规划与设计
- UE4遇到的各种奇葩问题
- xv6 6.S081 Lab5: cow
- CREO:CREO软件之零件【工具(调查/模型意图/实用工具)】、【视图(可见性/方向/模型显示/显示/窗口)】的简介及其使用方法(图文教程)之详细攻略
- DataX及DataX-Web
- 电子取证和司法鉴定笔记
- 计算机组成与系统结构——期末复习
- 我通过Python给我们班写了个电子考勤系统!室友为啥孤立我了?
- 关于字符集(彻底搞清楚一个中文占几个字节?)
- XFTP与XSHELL系统错误,缺少MSVCP110.DLL与MSVCR110.DLL解决办法
热门文章
- ORACLE删除表分区和数据
- 95-910-148-源码-FlinkSQL-Flink SQL自定义聚合函数
- 【flink】Flink 1.12.2 源码浅析 :Task数据输出
- 【maven】The forked VM terminated without saying properly
- 【ElasticSearch】es ResourceWatcherService 的 初始化 启动 源码解析
- 【Kafka】Kafka 配置 SASL_SSL jks鉴权验证方式
- 【Flink】FlinkException The file LOG does not exist on the TaskExecutor
- 01-浏览器同源政策 以及 什么是跨域?怎么解决跨域问题?
- 20-100-010-安装-Flink集群安装 flink-1.4.0-bin-hadoop27-scala_2.11
- List实现类的特点和性能分析