473,386 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

Jul 19 '05 #1
5 4380
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
"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
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Ralf W. Grosse-Kunstleve | last post by:
****************************************************************************** This posting is also available in HTML format: http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html...
6
by: RainBow | last post by:
Greetings!! I introduced the so-called "thin-template" pattern for controlling the code bloat caused due to template usage. However, one of the functions in the template happens to be virtual...
1
by: Lumpierbritches | last post by:
Thank you in advance. Is there a way to programmatically fill an Unbound Form with a command button, using Queries built? I have a program that has about 10 different queries that all fill the...
2
by: Greg Strong | last post by:
Hello All, Is there any fix to apparent MDB file size bloat when creating data through the manipulation of recordsets in VB? I'm trying to create sample data by manipulating the raw data set...
6
by: Abubakar | last post by:
Hi, I'm working on a project in unmanaged c++. I was writing all (most of) my code in header files, that is, no seperation of code in header and cpp files, as usually is done in c++. I feel pretty...
3
by: Ray Gardener | last post by:
I searched around but couldn't find any previous discussion on this, so... I have a macro that implements a common memory disposal function, e.g.: #define safe_free(void* pv) if(pv) {...
4
by: Peyman | last post by:
Hi, I was reading the source code of an implementation of STL by HP company 1994, and Silicon Graphics Computer Systems, Inc. 1996, 1997. Which I found that for implementing a Linked List, they...
48
by: Tony | last post by:
How much bloat does the STL produce? Is it a good design wrt code bloat? Do implementations vary much? Tony
12
by: Trish | last post by:
I just had a bad experience using MS Word as an HTML editor. It bloated more than 200% so I could barely recognize the essential statements; and it introduced more than 14,000 errors. Also,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.