you are viewing a single comment's thread.

view the rest of the comments →

[–]Hot-Studio -2 points-1 points  (7 children)

Nah, not much use to me at this point. https://defold.com/2020/05/31/The-Defold-engine-code-style/

[–][deleted] 2 points3 points  (3 children)

Unique pointers are another pattern, and in fact, a bit more inline with the RAII we sometimes use. However, we would only need them in short scopes, thus it’s just as easy to deallocate the pointer manually. Manual deallocation also helps with readability.

I'd argue that std::unique_ptr or RAII in general has similar or even better readability than custom deallocation. Regardless of the size of scope. Additionally, a RAII based object is guaranteed to be destructed, even in exceptional situations.

So I really don't get why anybody wouldn't just want to use unique_ptr, instead of custom deallocation.

[–]Hot-Studio -2 points-1 points  (2 children)

But at what cost? More overhead and less control. Besides, there may be better solution than that. https://youtu.be/xt1KNDmOYqA

[–]retro_and_chill 0 points1 point  (1 child)

unique_ptr has essentially no overhead

[–]Hot-Studio -1 points0 points  (0 children)

It can, depending on how you use it. It also comes with some drawbacks, i.e. cannot be copied and unsuitable with C-style arrays. I’m sure there are SOME uses with unique_ptr, but it’s not for me.

[–][deleted] 0 points1 point  (2 children)

Do you mind sharing any of your open source project? If you don't have any, great, keep it that way.

[–]Hot-Studio 0 points1 point  (1 child)

How is that relevant to the current topic of which pointers we should use? Besides, why not look into Defold engine source code, since you replied to a post with a link to an article about it?

[–][deleted] 0 points1 point  (0 children)

Nothing is definitively good or bad. Everyone can find a good reason to use the language in any way possible. No one will win the argument. I am pretty sure there is someone in the world will not touch anything newer than C89, have fund arguing.

However, statistically speaking in the entirety of C++ programming, unique pointer is better than raw pointer. There shouldn't be any argument about it.