我目前在用C++做算法4,我用shared_ptr管理动态数组,以此实现类似Java的引用那样的垃圾回收,而不用每次手动delete [],请问这个思路有什么不足吗?
认证0级讲师
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
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