STL & reducing code bloat

Discussion in 'C++' started by Salvador I. Ducros, Jul 28, 2003.

  1. Greetings all,

    I was hoping someone might be able to point me in the right direction. I'm
    currently
    using std::vector to maintain several lists whose objects are of unrelated
    types (classes).
    I've seen mentioned here and there a technique that uses 'void *' and
    something called
    'template specialization' that would reduce the amount of code generated for
    the
    std::vector's.

    I don't fully understand how I might use std::vector<void *> without having
    to constantly
    cast object pointers to and from 'void *'. Might someone point me to a
    resource that
    would explain this technique in greater detail?

    Regards,

    Salvador Ducros
    Salvador I. Ducros, Jul 28, 2003
    #1
    1. Advertising

  2. Salvador> I was hoping someone might be able to point me in the right
    Salvador> direction. I'm currently using std::vector to maintain
    Salvador> several lists whose objects are of unrelated types
    Salvador> (classes). I've seen mentioned here and there a technique
    Salvador> that uses 'void *' and something called 'template
    Salvador> specialization' that would reduce the amount of code
    Salvador> generated for the std::vector's.

    I guess the first question to ask is this: Is the amount of code
    in question a serious problem?

    --
    Andrew Koenig,
    Andrew Koenig, Jul 29, 2003
    #2
    1. Advertising

  3. Salvador I. Ducros

    Evan Guest

    "Salvador I. Ducros" <> wrote in message news:<KHhVa.108206$>...
    > Greetings all,
    >
    > I was hoping someone might be able to point me in the right direction. I'm
    > currently
    > using std::vector to maintain several lists whose objects are of unrelated
    > types (classes).
    > I've seen mentioned here and there a technique that uses 'void *' and
    > something called
    > 'template specialization' that would reduce the amount of code generated for
    > the
    > std::vector's.
    >
    > I don't fully understand how I might use std::vector<void *> without having
    > to constantly
    > cast object pointers to and from 'void *'. Might someone point me to a
    > resource that
    > would explain this technique in greater detail?
    >
    > Regards,
    >
    > Salvador Ducros
    >


    If you are storing a known set of types, you might check out Boost's
    tuple class: http://boost.org/libs/tuple/doc/tuple_users_guide.html
    Evan, Jul 29, 2003
    #3
  4. Salvador I. Ducros

    Evan Guest

    Doh... I posted another post, but forget to finish it first... (and I
    can't reply to it directly as I'm using Google and it takes forever to
    update)

    Anyway, about Boost::tuple, I'm not sure if that'll help. It probably
    won't reduce code bloat anyway... But it may, so that's why I
    suggested it.
    Evan, Jul 29, 2003
    #4
  5. "Evan" <> wrote in message
    news:...
    > Doh... I posted another post, but forget to finish it first... (and I
    > can't reply to it directly as I'm using Google and it takes forever to
    > update)
    >
    > Anyway, about Boost::tuple, I'm not sure if that'll help. It probably
    > won't reduce code bloat anyway... But it may, so that's why I
    > suggested it.


    I'll check it out. It sounds like it might be useful for something else I've
    been working on. Thanks,

    Salvador I. Ducros
    Salvador I. Ducros, Jul 29, 2003
    #5
  6. In article <RuzVa.5892$>,
    Salvador I. Ducros <> wrote:

    | "Andrew Koenig" <> wrote in message
    | news:...
    | > Salvador> I was hoping someone might be able to point me in the right
    | > Salvador> direction. I'm currently using std::vector to maintain
    | > Salvador> several lists whose objects are of unrelated types
    | > Salvador> (classes). I've seen mentioned here and there a technique
    | > Salvador> that uses 'void *' and something called 'template
    | > Salvador> specialization' that would reduce the amount of code
    | > Salvador> generated for the std::vector's.
    | >
    | > I guess the first question to ask is this: Is the amount of code
    | > in question a serious problem?
    | >
    | > --
    | > Andrew Koenig,
    |
    | No. Not a problem. I simply wanted to educate myself about ways to avoid
    | code bloat when using STL (& templates in general) for if and when it ever
    | becomes a problem.
    |
    | On the other hand, I do find the amount of code being generated a bit much.
    | I was able to reduce the code size significantly by using a generic
    | container
    | implemented in plain C. I'd rather use STL which is why I started searching
    | for ways of reducing code bloat when using STL (std::vector in this specific
    | case).

    Bjarne Stroustrup's excellent text: The C++ Programming Language"
    devotes a small section to this technique. The Metrowerks
    implementation goes beyond the "void* optimization" and implements this
    code size optimization across all pods (e.g. unsigned short and short
    also share the same code).

    --
    Howard Hinnant
    Metrowerks
    Howard Hinnant, Aug 5, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RainBow
    Replies:
    6
    Views:
    362
  2. Steven T. Hatton

    Exceptions and object code bloat

    Steven T. Hatton, Nov 27, 2006, in forum: C++
    Replies:
    5
    Views:
    360
    =?iso-8859-1?q?Kirit_S=E6lensminde?=
    Nov 28, 2006
  3. Tony
    Replies:
    48
    Views:
    1,146
    Mathias Gaunard
    Dec 12, 2006
  4. BGB / cr88192

    hmm: code bloat?...

    BGB / cr88192, Jan 5, 2010, in forum: C Programming
    Replies:
    16
    Views:
    596
    BGB / cr88192
    Jan 6, 2010
  5. Lawrence D'Oliveiro

    Managed-Code Bloat

    Lawrence D'Oliveiro, Jun 6, 2011, in forum: Java
    Replies:
    37
    Views:
    1,016
Loading...

Share This Page