请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:CC2540 我有一个用于存储 uint32值和指针的链接列表。 我能够保存28个值、然后它报告没有可用的内存。 这是否正常?
我还有一个用于控制 LED 条的例程、我的例程占用了长度(m)并驱动这些 LED。
如果我将29m 作为参数、它将挂起。
我已经了解了我的代码、不知道为什么29个会挂起 MCU。
是否有方法读取内存中可用的字节数?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
我更改了链接列表以使用静态数组[100]、它正常工作。
但是、我更喜欢使用动态数组而不是静态大小数组。
我通常使用 gcc 编译器测试我的代码、然后复制到 MCU 固件。 GCC 编译器、我可以创建包含10000个条目的列表。
#include
#include
#include
#include
typedef signed char int8; //!<有符号8位整数
typedef unsigned char uint8;//!<无符号8位整数
typedef signed short int16;//!<有符号16位整数
typedef unsigned short uint16;//!<无符号16位整数
typedef signed long int32;//!<有符号32位整数
tyf unsigned long uint32; //!<无符号32位整数
typedef unsigned char bool; //!<布尔数据类型
#define false 0
#define true 1
#define RESET_list {temp = first;自由列表(temp);first = 0;}
struct node{
uint32失效时间;
struct node *next;
};
typedef struct node node;
node *head、*first、*temp、*view;
uint32 readValue (node* readptr、int index){
if ( readptr != NULL ){
while (index---){
readptr = readptr ->下一步;
}
返回 readptr -> laptime;
}
返回0;
}
bool appendValue (uint32 value){
head =(节点*) malloc (sizeof (node));
if (head!= NULL){
head->laptime =值;
if (first!= 0){
head->next = NULL;
temp->next =标题;
温度=头部;
} 否则{
First = temp = view = head;
temp->next = NULL;
}
返回 true;
}
返回 false;
}
void 自由列表(节点*货币){
节点* freetemp;
if (CURR!= NULL){
while (curr->next!= NULL){
freetemp =当前->下一个;
免费(货币);
当前= freetemp;
}
免费(货币);
}
}
int countList (node* CURR){
INT 计数;
if (CURR == NULL){
返回0;
} 否则{
计数= 1;
while (curr->next!= NULL){
CURR = CURR_>NEXT;
count++;
}
返回计数;
}
}
int main (void)
{
int i;
RESET_list
对于(i=0;i<10000;i++){
appendValue(i);
}
视图=第一个;
对于(i=0;i<10000;i++){
printf (“R%d:%lu\n",i,readValue (View,i));
}
视图=第一个;
printf ("计数:%d\n"、countList (视图));
RESET_list
视图=第一个;
printf ("计数:%d\n"、countList (视图));
返回0;
}