Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

doodah2001

STL vs your own

This topic is 6004 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

I''m just curious as to how many people use the STL for such things as lists, maps, and vectors vs. creating their own customized list or vector class and I was also wondering why ya''ll choose one type over the other. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
I use the STL because it works. I''ve written about a zillion linked list implementations in my life and don''t ever want to again

Actually, I think everyone should write there own list classes at least once in their lifetime. Write a single linked list, doubly linked list, array, and hash table class, and use it in a project. It''s good practice and you can really see some of the time/space tradeoffs.

Share this post


Link to post
Share on other sites
I use the STL containers almost exclusively. They have many great features and chances are that even if you''re a professional programmer, the STL is probably written better than what you would right, especially if you wanted all of the features the STL provides.

I''ve seen lots of tests showing that the STL containers are just as fast as their non-STL counterparts (i.e. vector<> is as fast as an array).

I would say that the only time you need to write your own data structure is when you need a feature that the STL does not provide for you.

Russell

Share this post


Link to post
Share on other sites
Just why would you waste time to reimplement something that already exists and works ?

As to choosing vector or list. Well, unless you REALLY need to be able to insert elements in the middle of your structure, go for the vector.

Share this post


Link to post
Share on other sites
I use the standard C++ library unless I can''t (e.g. kernel-mode code). That''s pretty much the only reason not to use a standard class -- assuming, of course, that an appropriate standard class exists. Oh, I also use the various hashed containers that many library implementations have.

The well-defined interfaces and thoroughly tested code are a boon.

Share this post


Link to post
Share on other sites
I prefer to use home-made classes, mainly for 2 reasons:
1- STL syntax is crappy
2- I can customize my own classes to do exactly what i want them to do, and to be optimized for the use i have. For example, in the game im working on, I always access the first, same or next element of a list, so I''ve build a simple multi- linked list that garanteed those 3 access operations to be done in O(1).



Share this post


Link to post
Share on other sites
quote:
For example, in the game im working on, I always access the first, same or next element of a list, so I''ve build a simple multi- linked list that garanteed those 3 access operations to be done in O(1).

What the hell are you on about?

Accessing the next, previous, or same item in a list is a constant-time operation anyway.

@_@.





As for which container to pick, it''s almost always obvious, because the containers all have different properties.

Share this post


Link to post
Share on other sites
I use the STL because it works and its fast (most STL implementations are extremely efficient, so unless you have ridiculously specific needs for containers/iterators/string class/etc you''re unlikely to write code that surpasses their efficiency without putting in a ton of work, years of debuggin, etc).

It is somewhat annoying that it doesnt fit with my standard syntax usage (I tend to use upper-case-first class names like Vector..not vector), but no biggie; that''s always a potential issue with any API.

...

I second OldGuy''s claim that people should try implementing the classic data structures and algorithms STL abstracts just to be sure they know what''s going on ''underneath the hood''. In most cases, however, once you get them working I think you should just toss them out and go with the STL implementations.

Share this post


Link to post
Share on other sites
STL all the way
But, I would suggest to anyone who doesn't know how to code a linked list, stack, queue, hash table, etc. I have created my own classes for those abstract data types at one time or another. It is a GREAT learning experience, so do it!!

Good Luck!

EDIT: Forgot to say why I use STL mainly for:

  • It's thoroughly tested

  • It's probably more optimized than the ones I have made

  • It's a standard

  • Very robust

  • It fits my needs

  • I don't want to completely reinvent the wheel; just learn how it works



Edited by - Floppy on January 31, 2002 10:51:30 PM

Share this post


Link to post
Share on other sites
I prefer to not use STL.

Its naming convention completely conflicts with my normal one, and writing a wrapper to get around this would be a lot of overkill for little gain. But that''s not the main reason.

The main reason is that I prefer to have simple data structure templates which, while not necessarily QUITE as optimal performance-wise as STL, are more tailored to my needs on all levels, including interface, behavior, and storage. This tailoring means I can create data structure classes which are lightweight, being only as complex as I need them to be and nothing more.

In my case, the small speed gains and increased "standardness" of moving over to the STL are not worth the sacrifice I incur in terms of control. Working with third-party libraries for certain pieces of functionality is one thing, and when such libraries serve a specific problem domain and have a solid well-defined interface, I wholeheartedly endorse that. But the STL falls into the land of glue code, and that''s a completely different story as far as I''m concerned.

The STL is a very powerful and very efficient template library, but it''s a massive thing since it''s intended to be all things to all people. In contrast, I use a set of lightweight data structures that are entirely contained in a single header of less than 1000 lines, they perform decently and I have complete control over them. They fit my code better than the STL does, and that''s what matters.

To put it another way, yes reinventing the wheel is generally a bad idea, but it''s also a bad idea to use a truck tire when you don''t own a truck.

I don''t want to turn this into a religious war, since I''m fine with people either choosing to use the STL or choosing not to use it; everyone has their reasons. So by the same token, it''d be really nice if some people on this board (and elsewhere) would stop treating anyone who deliberately chooses not to use the STL as if they were somehow inferior.

Library choice, like language choice, is up to personal preference.

- Chris

Share this post


Link to post
Share on other sites

  • 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!