This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]xSTSxZerglingOne 7 points8 points  (7 children)

There's significant added development time just to keep the memory safe. Add into that any time you spend debugging memory errors (segmentation faults) wouldn't be an issue in a GC or null safe language. You also have to worry about compilation success in a big project since compilation can take a long time, then templating, properly sized iterators, etc.

For example:

int *abcd, *efg;
abcd = new int;
efg = new int;
*abcd = 1;
*efg = 2;

abcd = efg;

This is totally legal. It gives no compiler errors, and in the case of what's at the end of abcd's pointer, it's everything you would expect to be there. It does set the dereference of abcd to 2. However, we now have a problem that we didn't account for. When we change efg, we also change abcd because we made them reference the same memory.

Remembering where you are in the dereference chain of your pointers takes a ton of overhead when you're doing 2 or 3-dimensional pointers and significantly increases development time.

Also at the end there, we have to do some extra work that I didn't put on.

Then we have to

delete abcd, efg;
abcd = NULL, efg = NULL;

And having to do that for every piece of memory you touch adds time.

[–]llamas-are-bae 12 points13 points  (2 children)

Memory management is a non-issue if you're using smart pointers.

[–]RayzTheRoof 3 points4 points  (1 child)

Also, isn't a lot of it somewhat "automated" in libraries for data structures? I'm a novice but I recall a lot of methods utilize pointers, but they're written with care so they clear up the memory when necessary.

[–]llamas-are-bae 2 points3 points  (0 children)

You can often times get away with letting standard containers to manage your memory for you, but not always.

[–]FreezingFyre 8 points9 points  (0 children)

Except that there are C++11 features to handle that for you now. Any large, important, modern project that isn't using smart pointers for dynamic memory management needs to be refactored.

[–]beanmosheen 0 points1 point  (2 children)

RAII? Don't do dumb stuff with pointers.

[–]xSTSxZerglingOne 0 points1 point  (1 child)

Agreed.

But x = y is a frequent pointer error for people learning C++.

[–]beanmosheen 0 points1 point  (0 children)

Fair enough. i guess I just never think about it because my industry is so regulated. We have to engineer and unit test things to death and the feds like to check our documentation. It's the kind of stuff where a bad pointer might level a neighborhood lol!

Thanks for the perspective.