C++ 中的动态内存分配

发布于 2024-08-10 23:10:39 字数 41 浏览 3 评论 0原文

在动态内存分配方面,“删除”和“处置”C++ 运算符之间有什么区别?

What is the difference between the 'delete' and 'dispose' C++ operators with regards to dynamic memory allocation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

阳光下慵懒的猫 2024-08-17 23:10:39

delete 将释放在非托管 C++ 中动态分配的内存
Dispose 将强制自定义对象在托管 C++/CLI 中实现一次性对象的维护

delete will free memory dynamically allocated in unmanaged C++
Dispose will force custom object implemented maintenance of disposable objects in managed C++/CLI

瞄了个咪的 2024-08-17 23:10:39

标准 C++ 中没有 dispose 运算符(或标准函数,或类似的任何东西)——您是否正在考虑某种特定的专有框架,例如 Microsoft 的 .NET“托管 C++”? delete 标准,它确实是一个运算符,并且必须表现在任何符合标准的实现中都像这样——这是与运算符 dispose 的主要区别,也是与运算符 unicorn 的主要区别code>、toothfairysantaclaus,它们有很多共同点,因为这些都不存在!-) [[对不起弗吉尼亚... !]]

There's no dispose operator (or standard function, or anything of that ilk) in standard C++ -- are you thinking of some specific proprietary framework, such as Microsoft's .NET "managed C++"? delete is standard, it's indeed an operator, and must behave like this in any standard conforming implementation -- that's the main difference with operator dispose, and also the main difference with operators unicorn, toothfairy, and santaclaus, which have a lot in common since none of those exists!-) [[Sorry Virginia...!]]

绾颜 2024-08-17 23:10:39

我假设这与 .NET 托管 C++ 有关,因为标准 C++ 没有“处置”的意义。

删除会释放用于存储对象的内存;该内存返回到堆并可用于其他存储需求。

Dispose 将使对象有机会释放它获取的资源,例如文件句柄等。标准 C++ 将在析构函数中看到此类任务完成。

I'm assuming this is related to .NET managed C++ because standard C++ has no sense of "dispose".

Delete will release the memory used to store the object; this memory returns to the heap and can be used for other storage requirements.

Dispose will give the object the chance to release resources it acquired such as file handles, etc. Standard C++ would see this sort of task done in the destructor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文