Jump to content
  • Advertisement
Sign in to follow this  
Skute

Home grown or save your time?

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, im wondering whether it will pay to write my own list template class, or to use the one in the stl? Im writing my EntityManager class, so need to keep a list of entities. Not sure whether to write my own list class or not....

Share this post


Link to post
Share on other sites
Advertisement
I don't use STL, but I don't write an entire class or template either. I just add simple linked-list capability to things that need it. It's about 5-10 lines each for add, remove and rearrange.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kris_A
I don't use STL, but I don't write an entire class or template either. I just add simple linked-list capability to things that need it. It's about 5-10 lines each for add, remove and rearrange.


So, let's see... 5-10 lines each means 30 lines, add to this the traversal code (either 10 lines once and 10 lines for each traversal, or 60 lines once to implement an iterator and no additional work per traversal), the code to replace various standard library algorithms (copy, for_each) which represents quite a nice bit of code, this adds up to 500 lines. Now, writing, debugging, profiling and optimizing 500 lines of code to reach the same level as the STL ought to take you two days. If you want advanced functionality (and an optimized one at that) such as templated allocators, sorting, wrapping push_front and push_back iterators, add a couple of weeks.

If std::list provides what you need, use it. If you need something it doesn't provide, but can be built on top of it, then use it and build that thing on top of it. Only if you have needs so specific, precise and exotic that the standard implementation does not provide them at all, should you roll out your own implementation. Otherwise, you're just spending more time to get an often inferior result.

Share this post


Link to post
Share on other sites
Quote:
this adds up to 500 lines. Now, writing, debugging, profiling and optimizing 500 lines of code to reach the same level as the STL ought to take you two days

Well, it doesn't. If I wanted to use STL then I would. If I wanted someone to tell me what to do, I would be asking a question not answering one. If Skute doesn't want to do it the same way, that's fine by me...

Share this post


Link to post
Share on other sites
Quote:
Original post by Skute
Hi, im wondering whether it will pay to write my own list template class, or to use the one in the stl?

Im writing my EntityManager class, so need to keep a list of entities. Not sure whether to write my own list class or not....


Want to create a game? use the STL.
Have a deep craving to battle with pointers and do silly misstakes but learn how a linked list work? Write your own, then use the STL instead.

As for the intrusive approach mentioned earlier, simply don't to that you'll end up with a class that has severe personality problems and tries to make quite a lot more than one thing. (Oh, yeah there actually exist scenarios where it makes sense, bulk PC programming isn't one of them though.)

Share this post


Link to post
Share on other sites
Quote:
Original post by Kris_A
Well, it doesn't. If I wanted to use STL then I would. If I wanted someone to tell me what to do, I would be asking a question not answering one. If Skute doesn't want to do it the same way, that's fine by me...
Don't get defensive. You're just a bad software developer is all. You really shouldn't be dispensing advice, given the apparently poor quality of the software development decisions you make (at least in this case).

Share this post


Link to post
Share on other sites
Quote:
Original post by Skute
Hi, im wondering whether it will pay to write my own list template class, or to use the one in the stl?


If your goal is to learn to write a linked list - write one.
If your code happens to need a linked list, use the one in the library - it works, is standard, feature-reach and integrates with the rest of the library.
If you can demonstrate std::list is unsuitable to your needs - consider writing a custom allocator: that's often the customization people really need.
If an allocator still doesn't cut it - go back to writing your own, but try to conform to the STL's container interfaces and concepts, for familiarity (which, at that level, you would have) and integration purposes.

Quote:
Im writing my EntityManager class, so need to keep a list of entities. Not sure whether to write my own list class or not....


Then don't. You've got more important things to do, don't you?

Quote:
Well, it doesn't. If I wanted to use STL then I would. If I wanted someone to tell me what to do, I would be asking a question not answering one. If Skute doesn't want to do it the same way, that's fine by me...


You hadn't justified the validity of your approach, making your personal opinion of little help to Skute and leaving you wide open to a refutation. There is no need to take personally the fact that ToohrVyk explained the downsides of your solution, for Skute's benefit if not for yours.

Share this post


Link to post
Share on other sites
Writing your own linked list class is not very hard to do. If you feel like doing it, go ahead and do it for the learning. Don't be afraid of making "silly mistakes", and don't be afraid of pointers. If you do it right, it will work and will most likely be as fast as the STL linked list in practice.

Its just not as practical as having a standard templated linked list class that is compatible with all the other functionalities of the STL.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!