OutpostUniverse / OPHD

OutpostHD - Open source remake of Sierra On-Line's Outpost
BSD 3-Clause "New" or "Revised" License
110 stars 21 forks source link

Replace uses of `new` and `delete` #480

Open DanRStevens opened 4 years ago

DanRStevens commented 4 years ago

The project has many occurrences of new and delete. These are best avoided in modern C++ code. Many of these (possibly all) can likely be replaced by std::unique_ptr. As a bonus, using std::unique_ptr may make some destructors empty, allowing us to omit them.

Reference: C.149: Use unique_ptr or shared_ptr to avoid forgetting to delete objects created using new

ldicker83 commented 4 years ago

Generally in agreement here. There are cases where pointers make sense but I'm somewhat unfamiliar with so-called smart pointers. Seems now is as good a time as any to start moving the code in that direction.

DanRStevens commented 8 months ago

Did a quick scan of the code to see where we have naked new:

Additionally, our choice of some external code forces some uses of new on us:

ldicker83 commented 8 months ago

I do want to move away from TinyXML and reimplement with json. I've had a lot of success with https://github.com/nlohmann/json for json parsing, it feels very natural in C++.

Micropather we may want to consider adjusting to use without raw memory management. Might make sense to fork it for our purposes as the library really doesn't change much if at all or pull it out of the OPHD repository and add it as a submodule from its original source: https://github.com/leethomason/MicroPather

I think I added the code in before I really understood how to use git submodules :/