问题描述
我,我想许多人一样,都取得了巨大成功,使用像RAII,等等。然而,包装内存管理更容易实现,当你有析构函数,类,运算符重载,等等。
I, and I think many others, have had great success using smart pointers to wrap up unsafe memory operations in C++, using things like RAII, et cetera. However, wrapping memory management is easier to implement when you have destructors, classes, operator overloading, et cetera.
有关原始C99有人写,你可以点在哪里(没有双关语意)与安全的内存管理,帮助?
For someone writing in raw C99, where could you point (no pun intended) to help with safe memory management?
感谢。
推荐答案
这是很难处理的纯粹的C智能指针,因为你没有语言的语法来备份使用。大多数我见过真的不工作,因为你没有运行时,对象离开范围,这实在是什么使智能指针析构函数工作的优势尝试。
It's difficult to handle smart pointers in raw C, since you don't have the language syntax to back up the usage. Most of the attempts I've seen don't really work, since you don't have the advantages of destructors running when objects leave scope, which is really what makes smart pointers work.
如果你真的很担心这个,你可能想干脆直接使用和完全绕过智能指针要求。
If you're really worried about this, you might want to consider just directly using a garbage collector, and bypassing the smart pointer requirement altogether.
这篇关于智能指针/安全内存管理对于C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!