On Monday, 26 October 2015 13:00:40 UTC+2, Rosario19 wrote:
> On Mon, 26 Oct 2015 11:55:01 +0100, Rosario19 wrote:
>
> >On Mon, 26 Oct 2015 10:51:12 +0100, Rosario19 <R...@invalid.invalid>
> >wrote:
> >
> >>c++ stl vector--- how to make difficult what is easy
> >>
> >>constructor: call call call call call never end
> >>
> >>than
> >>vector<int> b;
> >>
> >>where is b.len the len of vector as u32
> >> and
> >> b.size the size of the vector as u32
> >> [effective mem position already allocated]
> >
> >?
> >pheraps i understand...
> >
> >they are not there because someone think programmer can change these
> >value and what can change these value is only class vectror
> >
> >fear pure fear
>
> in all my classes i use [pheraps not are too many and are small]
> i never make the above error in all my life
> at last believe that
> and all type in my classes are public
> and in every part of the code i can change them
> [admit rarely chage them out the classes function]
By my measurements the C++ standard libraries provide excellent
performance. Non-naive usage of those is quite hard to beat with
explicit C code.
All C++ standard library containers have 'size()' member
function in interface so we do not need to dig in their implementation
details every time. We can replace one container with other with
minimum changes needed and that saves time. Compiler will inline
and optimize these well. Manual optimizations are almost never needed.
Let's go to details? Implementation of 'vector::size()' may be something
like that:
return static_cast<size_type>( end_ - begin_ );
Likelihood of 'size()' being calculated instead of stored is because
majority of algorithms and range based 'for' use 'begin' and 'end'
more often than 'size' and storing all 3 is waste of space.
The 'size' of 'std::string' can be taken from some data member,
but when it uses small string optimization then it may be
conditionally stored as 7 bits and when not then in 32. Again it is
not your business, you are supposed to call 'size()'.
So it is you who are in error here. In general better do some real
benchmarks and post results (don't do these with debug build like
noob). Groundless uneducated whining is uninteresting.