7 ms·
So what? Smart pointers are not a superior alternative to raw pointers. They are a memory management device that you may or may not want to use. For example a
by GuB-42 4y ago
So what? Smart pointers are not a superior alternative to raw pointers. They are a memory management device that you may or may not want to use.
For example a pattern that I think is common in low level game programming is to allocate a big chunk of memory containing a many objects and deallocating them all at once when you are done with them, let's say a level with its maps, textures, entities, etc... It doesn't really make sense to pass individual objects (ex: a single texture) using smart pointers because you can't delete them individually, in fact, unless you have overloaded the delete operator, it will crash if you do.
In fact, if you never use raw pointers, I think that you are better off using another language than C++ if you can. Manual memory management is a big part of what gives C and C++ its performance (at a cost). If you don't do that, there are languages with well optimized garbage collectors that will outperform you.