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 

templates

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





PostPosted: Sun Feb 26, 2006 7:06 pm    Post subject: templates Reply with quote



When I use

vector<int>
vector<int*>
vector<anything*>

I have 3x code, or because of same size:
sizeof int == sizeof any pointer
I have only 1x code?



and another question:

I use vector<int> somewhere.
If I use (in another position) list<int>, it increases the binary more
that I use again vector<int>?
Back to top
Victor Bazarov
Guest





PostPosted: Sun Feb 26, 2006 8:06 pm    Post subject: Re: templates Reply with quote



Chameleon wrote:
Quote:
When I use

vector<int
vector<int*
vector<anything*

I have 3x code, or because of same size:
sizeof int == sizeof any pointer
I have only 1x code?

You have exactly 1x code which you actually use. If you use
'vector<int>::push_back', it will be generated. If you don't
use 'vector<anything*>::clear', it will not be generated.

Quote:
and another question:

I use vector<int> somewhere.
If I use (in another position) list<int>, it increases the binary more
that I use again vector<int>?

Yes, most likely.

V
--
Please remove capital As from my address when replying by mail
Back to top
Phlip
Guest





PostPosted: Sun Feb 26, 2006 9:06 pm    Post subject: Re: templates Reply with quote



Chameleon wrote:

Quote:
When I use

vector<int
vector<int*
vector<anything*

I have 3x code, or because of same size:
sizeof int == sizeof any pointer
I have only 1x code?

Some compilers advertise their template implementations can fold identical
code, as a hedge against binary bloat.

Some template libraries use secret internal typecasts to bust all pointers
down to integers, process them, and cast them back.

You should never do that in your own code, never rely on it, and you should
only rarely worry about code footprint.

Quote:
and another question:

I use vector<int> somewhere.
If I use (in another position) list<int>, it increases the binary more
that I use again vector<int>?

Yes. list and vector are completely different, and will always express
different opcodes into your binary. (And always prefer vector without a
reason to use something else.)

However, all these guestimates hit the C++ "As If" rule. It states the
compiler can do anything it likes so long as the resulting code performs As
If it had obeyed the ISO C++ Standard's compilation model. (Put another way,
this permits the ISO committees to define C++ in terms of hardware, as a
convenience, without the definition growing wildly abstract.)

However however, the most important resource to optimize is programmer time.
Don't spend too much time worrying about the speed or size of each line of
code you write. Do worry about code clarity. It's easier to make beautiful
code fast and small than to make fast or small code beautiful.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
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.