C 我怎样才能知道我在堆里有多少地方,怎样才能清除它?

C 我怎样才能知道我在堆里有多少地方,怎样才能清除它?,c,memory,linked-list,heap,C,Memory,Linked List,Heap,我怎么知道我在堆里有多少位置? 如果我已经运行了许多带有链表的代码,但没有使用free()函数,我如何清理它 例如,我已经运行了这段代码,但没有使用free()函数。 我如何清理该函数生成的内容,以及如何检查我现在在堆中有多少位置 void main() { int i, num,item; LNODE* newNode; LIST lst; lst = makeEmptyList(); printf("Please enter the numbers of the nodes: "); sc

我怎么知道我在堆里有多少位置? 如果我已经运行了许多带有链表的代码,但没有使用free()函数,我如何清理它

例如,我已经运行了这段代码,但没有使用free()函数。 我如何清理该函数生成的内容,以及如何检查我现在在堆中有多少位置

void main() {

int i, num,item;
LNODE* newNode;
LIST lst;
lst = makeEmptyList();
printf("Please enter the numbers of the nodes: ");
scanf("%d", &num);
printf("Please enter the value of the head: ");
scanf("%d", &item);
insertValueToHead(item, &lst);

for (i = 0; i < num-1; i++)
{
    printf("Please enter the value of the next node: ");
    scanf("%d", &item);
    newNode = createNewNode(item, lst.tail);
    AddToEndOfTheList(&lst, newNode);
}
printf("\n");
printList(&lst);
void main(){
int i,num,item;
LNODE*newNode;
列表lst;
lst=makeEmptyList();
printf(“请输入节点的编号:”);
scanf(“%d”和&num);
printf(“请输入标题的值:”);
scanf(“%d”项和项目);
将值插入表头(项目和lst);
对于(i=0;i
我如何检查我现在在堆中有多少位置

void main() {

int i, num,item;
LNODE* newNode;
LIST lst;
lst = makeEmptyList();
printf("Please enter the numbers of the nodes: ");
scanf("%d", &num);
printf("Please enter the value of the head: ");
scanf("%d", &item);
insertValueToHead(item, &lst);

for (i = 0; i < num-1; i++)
{
    printf("Please enter the value of the next node: ");
    scanf("%d", &item);
    newNode = createNewNode(item, lst.tail);
    AddToEndOfTheList(&lst, newNode);
}
printf("\n");
printList(&lst);
别担心

只需询问您需要什么并检查返回值

ptr = calloc(N, sizeof *ptr);
if (!ptr) exit(EXIT_FAILURE);
//... use ptr ...
free(ptr);

尽快释放资源(但不能更早)。知道您分配了多少内存的唯一方法是跟踪分配的总和。没有其他神奇的方法可以得到这个答案。请注意,如果您对分配进行求和,它将始终小于实际分配的数量,因为编译器可以自由地保留超过对齐目的请求的数量,minim嗯,分配大小,等等……简而言之,在C中,你负责内存管理。这意味着你必须跟踪分配的内容,并在使用完后释放内存。没有办法告诉运行时,“嘿,清理所有我忘记释放的内存。”