 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Salvador I. Ducros Guest
|
Posted: Mon Jul 28, 2003 10:44 pm Post subject: 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
[email]sducros (AT) rogers (DOT) com[/email]
|
|
| Back to top |
|
 |
Andrew Koenig Guest
|
Posted: Tue Jul 29, 2003 4:03 am Post subject: 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, [email]ark (AT) acm (DOT) org[/email]
|
|
| Back to top |
|
 |
Evan Guest
|
Posted: Tue Jul 29, 2003 4:42 am Post subject: Re: STL & reducing code bloat |
|
|
"Salvador I. Ducros" <sducros (AT) rogers (DOT) com> wrote
| Quote: | 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
[email]sducros (AT) rogers (DOT) com[/email]
|
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
|
|
| Back to top |
|
 |
Evan Guest
|
Posted: Tue Jul 29, 2003 4:46 am Post subject: 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.
|
|
| Back to top |
|
 |
Salvador I. Ducros Guest
|
Posted: Tue Jul 29, 2003 7:10 pm Post subject: Re: STL & reducing code bloat |
|
|
"Evan" <eed132 (AT) psu (DOT) edu> wrote
| Quote: | 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
[email]sducros (AT) rogers (DOT) com[/email]
|
|
| Back to top |
|
 |
Howard Hinnant Guest
|
Posted: Mon Aug 04, 2003 11:20 pm Post subject: Re: STL & reducing code bloat |
|
|
In article <RuzVa.5892$QsW1.959 (AT) news01 (DOT) bloor.is.net.cable.rogers.com>,
Salvador I. Ducros <sducros (AT) rogers (DOT) com> wrote:
| Quote: | "Andrew Koenig" <ark (AT) acm (DOT) org> wrote in message
news:yu99ptju6kte.fsf (AT) tinker (DOT) 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, [email]ark (AT) acm (DOT) org[/email]
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
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|