my list implementation is very slow

Pages: 123
I hope @cblack618 is taking note of how a professional operates when showing their gratitude.

(I like the topical corona/death/hope touch to improve on the old tried and true fuck/whore/bitch forms of endearment. It's always good to keep in tune with current affairs in these thank you for your help replies)
well thank you bitch (LMAO)
Getting back to the original question of list vs. vector (whether you're using your own or the std:: versions). It depends on what you're doing. It's expensive to insert into a vector at any location except the end. If you insert at location i then you have to move the items that were at locations i through size()-1 down one position. The smaller i is, the more expensive it gets. The same is true for removing items.

On the other hand, you can insert at any known position of a list in constant time. By "known position" I mean one where you already have an iterator pointing, or the head, or tail if your list maintains a tail pointer.

So the right choice really depends on what you're doing with it.

As for a "roll your own" vector, one aspect that usually gets lost on cplusplus.com when expanding the vector, will you construct new items in the expanded space? std::vector does not, which means it does not allocate space with new. When you add a new item, it uses placement new (have I got the term right?) to construct the object in uninitialized space.

As for the OPs vector implementation being twice as fast as std::vector, a friend of mine put it two ways:
1. The code can be made to run arbitrarily fast if correctness isn't an issue.
or
2. The biggest performance boost is when the code goes from "not working" to working."

Your code was fast but it didn't work for storing anything with a constructor and/or destructor. And let's not even talk about classes that throw exceptions.
Topic archived. No new replies allowed.
Pages: 123