STL or no STL

This is a discussion on STL or no STL within the C++ Programming forums, part of the General Programming Boards category; Hi, I've been looking at the code for ircd-hybrid recently, since I writing a state based server which uses CRLF ...

  1. #1
    sockets mad
    Join Date
    Mar 2002
    Posts
    126

    STL or no STL

    Hi,

    I've been looking at the code for ircd-hybrid recently, since I writing a state based server which uses CRLF terminated command lines just like an ircd does.

    All of the code in ircd-hybrid uses a custom written double linked list to manage all the client state information. I've started using STL containers (map and list).

    What I really wanted to ask is, am I doing anything wrong by using STL containers as opposed to the double linked list that is in ircd-hybrid?

    Since the ircd-hybrid code is all C and not C++, is that the only reason why they haven't used STL containers?

    Any input is greatly appreciated,

    Daniel

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    > Since the ircd-hybrid code is all C and not C++, is that the only reason why they haven't used STL containers?
    Probably, since C knows nothing of STL
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    sockets mad
    Join Date
    Mar 2002
    Posts
    126
    So there's no real advantage of creating your own linked list over using the STL one?

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Use STL whenever possible. If they're not sufficient for your needs, write your own.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    > So there's no real advantage of creating your own linked list over using the STL one?
    If you're writing in C, there is no choice but to write your own, or use someone elses non-standard library

    If you're writing in C++, there is little point in using your own, except for say learning purposes.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >So there's no real advantage of creating your own linked list over using the STL one?
    When you use the standard container classes, such as std::list, you are also free to use many generic template functions that work across all containers. You also use a standard interface that just about everyone will be familiar with. Both of these improve the quality of your code.

    On the flip side though, rolling your own custom linked list code can give you a little more flexibility/simplicity when writing compound data structures. A good example is a hashed list data structure I recently worked on. Using std::list gave me nothing but problems, but by rolling my own simple linked list, I got it working on the first try. Of course, that's a very specific exception. You should use the standard library whenever possible. I thought long and hard about not using it before writing my own, and I still might do a rewrite that uses it.
    My best code is written with the delete key.

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    Using std::list may result in some bloating of the executable if used with different data types. Stroustrup offers a solution to this somewhere in his book when the list's are of pointers, but I'm uncertain how many stl implementations use it. I don't think it would be a factor unless if it caused several MB's of bloat.

    Most cases when you do really need your own, you could also inherit from std::list.

  8. #8
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Quote Originally Posted by okinrus
    Most cases when you do really need your own, you could also inherit from std::list.
    Of course, in most cases when you need your own, you should not derive from std::list. It is not meant for public derivation, and in most cases public derivation is not necessary for enhancing the list. You could derive privately, but there are few if any advantages to doing so that couldn't be attained using containment, which is probably preferred.

    In most cases, simply adding global functions that take a list as a parameter (or use a template) is the best solution for enhancing an std::list.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stl containers allocation in heap or stack?
    By sawer in forum C++ Programming
    Replies: 9
    Last Post: 08-06-2006, 03:08 PM
  2. C Formatting Using STL
    By ChadJohnson in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2004, 04:52 PM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21