By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,496 Members | 1,280 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,496 IT Pros & Developers. It's quick & easy.

STL & reducing code bloat

P: n/a
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
sd*****@rogers.com

Jul 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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, ar*@acm.org
Jul 19 '05 #2

P: n/a
"Salvador I. Ducros" <sd*****@rogers.com> wrote in message news:<KH********************@news04.bloor.is.net.c able.rogers.com>...
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
sd*****@rogers.com


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
Jul 19 '05 #3

P: n/a
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.
Jul 19 '05 #4

P: n/a

"Evan" <ee****@psu.edu> wrote in message
news:3f**************************@posting.google.c om...
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
sd*****@rogers.com

Jul 19 '05 #5

P: n/a
In article <Ru*****************@news01.bloor.is.net.cable.rog ers.com>,
Salvador I. Ducros <sd*****@rogers.com> wrote:

| "Andrew Koenig" <ar*@acm.org> wrote in message
| news:yu**************@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, ar*@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
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.