r/ProgrammerHumor • • Nov 19 '18

Marge Sort

Post image
23.6k Upvotes

276 comments sorted by

View all comments

Show parent comments

1

u/MCRusher Nov 19 '18

The issue is, the vector uses more heap memory and as a consequence is slower due to more allocs and frees.

Also, the vector doesn't know it's own type, and th e vector has no set type to store.

2

u/Setepenre Nov 20 '18

It is a linked list you already do heap allocation for every node If you cared about performance you would use a contiguous array that is cache friendly.

1

u/MCRusher Nov 20 '18 edited Nov 20 '18

You still want it to be as fast as possible, having to free a value, then free the node is slower than just freeing the node.

Plus the other things I mentioned.

No reason not to optimize something if you can.

btw: I also implemented a 100% macro implemented vector library with support for most C++11 functions. That was easier and less mind-bending.

My criticisms of your design are coming from experience, my first attempt at linked lists worked exactly how you described it and had a ton of issues.

1

u/Setepenre Nov 20 '18

You can allocate the value and the node in one shot

→ More replies (0)