当不关心内存泄漏时,原始指针上共享指针
我只是想有人确认或否认我的思路。基本上,我想要一个只有在程序启动时才会创建的指针向量,并且在整个程序的一生中都需要。我看不到使用共享指针的理由,因为这会增加少量的开销,并且由于我不需要在程序关闭之前被交易的内存,因此我将从使用智能指针来开始。 。
我相信这是对的吗?在这种情况下,我真的想不出一个聪明的指针对我更有益的原因。
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是使用静态变量和原始指针的典型情况。我显然认为,指针的所有权总是很清楚的。
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.