当不关心内存泄漏时,原始指针上共享指针

发布于 2025-02-10 03:37:46 字数 176 浏览 0 评论 0原文

我只是想有人确认或否认我的思路。基本上,我想要一个只有在程序启动时才会创建的指针向量,并且在整个程序的一生中都需要。我看不到使用共享指针的理由,因为这会增加少量的开销,并且由于我不需要在程序关闭之前被交易的内存,因此我将从使用智能指针来开始。 。

我相信这是对的吗?在这种情况下,我真的想不出一个聪明的指针对我更有益的原因。

I would just like someone to confirm or deny my train of thought. Basically I want a vector of pointers that will be created only when the program boots up, and will be needed throughout the life of the program. I don't see a reason to use shared pointers as this will add a small amount of overhead, and since I won't need the memory deallocated until the program closes, I'll be gaining nothing from using a smart pointer to begin with.

Am I right in believing this? I genuinely can't think of a reason a smart pointer would be any more beneficial to me in this instance.

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

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

发布评论

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

评论(1

七婞 2025-02-17 03:37:46

这是使用静态变量和原始指针的典型情况。我显然认为,指针的所有权总是很清楚的。

This is a typical case for using a static variable and, yes, raw pointers. I obviously assume that the ownership of the pointers are always clear.

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