C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

STL & reducing code bloat

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Salvador I. Ducros
Guest





PostPosted: Mon Jul 28, 2003 10:44 pm    Post subject: STL & reducing code bloat Reply with 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]



Back to top
Andrew Koenig
Guest





PostPosted: Tue Jul 29, 2003 4:03 am    Post subject: Re: STL & reducing code bloat Reply with quote



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





PostPosted: Tue Jul 29, 2003 4:42 am    Post subject: Re: STL & reducing code bloat Reply with quote



"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





PostPosted: Tue Jul 29, 2003 4:46 am    Post subject: Re: STL & reducing code bloat Reply with 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.
Back to top
Salvador I. Ducros
Guest





PostPosted: Tue Jul 29, 2003 7:10 pm    Post subject: Re: STL & reducing code bloat Reply with quote


"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





PostPosted: Mon Aug 04, 2003 11:20 pm    Post subject: Re: STL & reducing code bloat Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.