内存管理 - 在C++11中用shared_ptr管理动态数组,这是个好的实践吗?
PHP中文网
PHP中文网 2017-04-17 14:38:51
0
2
487

我目前在用C++做算法4,我用shared_ptr管理动态数组,以此实现类似Java的引用那样的垃圾回收,而不用每次手动delete [],请问这个思路有什么不足吗?

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
Peter_Zhu

To manage a two-dimensional array, you can use std::vector<shared_ptr>. If it is one-dimensional, just use vector. If you can use smart pointers, you can of course give priority to using it

洪涛

Just use vector. It is generally fine to follow the RAII principle. Your goal should be memory safety rather than GC

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template