如何在C语言中执行自动内存管理? [英] How can I do automatic memory management in C?

查看:243
本文介绍了如何在C语言中执行自动内存管理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mallocfree中完成的C内存分配/取消分配.

In C memory allocation/deallocation done by malloc and free.

在C ++中,由newdelete完成的内存分配/取消分配.

In C++ memory allocation/deallocation done by new and delete.

C ++中有一些用于自动内存管理的解决方案,例如:

There are some solutions in C++ for automatic memory management like:

  • 智能指针.
  • RAII(资源获取正在初始化)
  • 引用计数和循环引用
  • ...

但是我如何在C语言中进行自动内存管理?

But how can I do automatic memory management in C?

在C中是否有用于 AUTOMATIC 内存管理的解决方案?

Is there any solutions for AUTOMATIC memory management in C?

对于C是否有任何准则或类似准则?

Is there any guidelines or something like that for C?

当我放弃free一个内存块时,我想要:

I want when I foget free a block of memory:

  • 我的代码无法编译

-或-

  • 内存自动释放

然后我说: 哦,C比C ++,Java和C#好. :-)

And then I say: Oh, C is better than C++, Java and C#. :-)

推荐答案

您可以使用 Boehm垃圾收集器库.

这篇关于如何在C语言中执行自动内存管理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆