是否可能引入自动引用计数(ARC)到C ++? [英] Is it possible to introduce Automatic Reference Counting (ARC) to C++?

查看:91
本文介绍了是否可能引入自动引用计数(ARC)到C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Objective C引入了一种名为ARC的技术,以免开发人员承担内存管理的负担。这听起来不错,我认为如果g ++也有这个功能,C ++开发人员会很高兴。




因此,如果LLVM3.0(Apple LLVM 3.0)编译器没有考虑保留,释放和自动释放,可以这样做,我认为g ++也可以释放C ++开发人员从内存管理的艰难的工作,是吗?



ARC引入C ++有什么困难吗? >

我的意思是:如果我们不使用智能指针,我们只需使用 new / new [] ,是否有可能编译器为我们做一些事情以防止内存泄漏?例如,将新的自动更改为智能指针?

解决方案

C ++具有 资源分配正在初始化(RAII) &智能使用这种方法可以避免显式资源管理。



C ++已经提供了 shared_ptr ,它提供引用计数。



此外,还有许多其他 智能指针 ,它使用RAII使C ++中的生活变得更容易。


Objective C has introduced a technology called ARC to free the developer from the burden of memory management. It sounds great, I think C++ developers would be very happy if g++ also has this feature.

ARC allows you to put the burden of memory management on the (Apple LLVM 3.0) compiler, and never think about retain, release and autorelease ever again

So, if LLVM3.0 can do that, I think g++ also can free C++ developers from the tough jobs of memory management, right?

Is there any difficulties to introduce ARC to C++?

What I mean is: If we don't use smart pointers, we just use new/new[], is it possible for a compiler to do something for us to prevent memory leaks? For example, change the new to a smart pointer automatically?

解决方案

C++ has the concept of Resource Allocation is Initialization(RAII) & intelligent use of this method saves you from explicit resource management.

C++ already provides shared_ptr which provides reference counting.

Also, there are a host of other Smart pointers which employ RAII to make your life easier in C++.

这篇关于是否可能引入自动引用计数(ARC)到C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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