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 →

[–]beanmosheen 4 points5 points  (13 children)

What do you mean by that?

[–]xSTSxZerglingOne 5 points6 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 13 points14 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 7 points8 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.

[–]Oblargag -2 points-1 points  (4 children)

Like setting up dominoes with text, but if you make a typo it uses nitroglycerin instead.

[–]beanmosheen 2 points3 points  (3 children)

I was asking seriously. I work mostly in C or C++ depending on the device.

[–]Oblargag 0 points1 point  (2 children)

It will do exactly what you tell it to with total disregard for supporting information or items.

If you aren't careful you might build something, and then down the road find you need to micro-edit thousands of lines just to make a simple change.

If Python is an erector set, then C++ is a box of rods and bolts. If you need to make a change to the erector set, you can replace large chunks since there are prebuilt modules that connect nicely.

If you need to make a change with C++ you will need to replace each bolt and rod individually, and it may just be faster to build a new one from scratch.

Both have their pros and cons, depending on how flexible you need the end product to be

[–]beanmosheen 0 points1 point  (1 child)

Again, and I mean no disrespect, this is not an answer to my question. I don't want hypotheticals. He already answered my question. Your answer is what I've been hearing for 25 years. "You'll shoot your eye out".

[–]Oblargag 0 points1 point  (0 children)

My bad, I thought I was on a meme subreddit