Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 19th, 2005, 04:50 PM
Salvador I. Ducros
Guest
 
Posts: n/a
Default STL & reducing code bloat

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
sducros@rogers.com



  #2  
Old July 19th, 2005, 04:50 PM
Andrew Koenig
Guest
 
Posts: n/a
Default Re: STL & reducing code bloat

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, ark@acm.org
  #3  
Old July 19th, 2005, 04:50 PM
Evan
Guest
 
Posts: n/a
Default Re: STL & reducing code bloat

"Salvador I. Ducros" <sducros@rogers.com> wrote in message news:<KHhVa.108206$zwL.21692@news04.bloor.is.net.c able.rogers.com>...[color=blue]
> 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
> sducros@rogers.com[/color]

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
  #4  
Old July 19th, 2005, 04:50 PM
Evan
Guest
 
Posts: n/a
Default Re: STL & reducing code bloat

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.
  #5  
Old July 19th, 2005, 04:52 PM
Salvador I. Ducros
Guest
 
Posts: n/a
Default Re: STL & reducing code bloat


"Evan" <eed132@psu.edu> wrote in message
news:3f25c666.0307282046.6d466131@posting.google.c om...[color=blue]
> 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.[/color]

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

Salvador I. Ducros
sducros@rogers.com



  #6  
Old July 19th, 2005, 05:04 PM
Howard Hinnant
Guest
 
Posts: n/a
Default Re: STL & reducing code bloat

In article <RuzVa.5892$QsW1.959@news01.bloor.is.net.cable.rog ers.com>,
Salvador I. Ducros <sducros@rogers.com> wrote:

| "Andrew Koenig" <ark@acm.org> wrote in message
| news:yu99ptju6kte.fsf@tinker.research.att.com...
| > 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, ark@acm.org
|
| 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
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles