 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Chameleon Guest
|
Posted: Sun Feb 26, 2006 7:06 pm Post subject: templates |
|
|
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
|
Posted: Sun Feb 26, 2006 8:06 pm Post subject: Re: templates |
|
|
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
|
Posted: Sun Feb 26, 2006 9:06 pm Post subject: Re: templates |
|
|
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 |
|
 |
|
|
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
|
|