KiLVaiDeN wrote:
Gavin Deane wrote:
Unless and until proven otherwise, both those concerns are secondary
to:
"Which option produces the most clearly human-readable code" and
"Which option enables you to get to the point where that code is
written, teted and error-free more quickly"
So, to the OP: consider the options in that context and choose
whichever answers those questions best. If you find, for example, that
it takes longer (including testing and debugging time) to write correct
code using containers of pointers, and that code is less clear to a
human reader, then use containers of objects.
Premature optimisation is the root of all evil and all that.
I am well aware of that. Both STL & pointer container generates human
readable code. If one wants to throw pointer_contain er from readibility
point of view , I can say it is matter of taste. I want from efficiency
point of view. I am not using unreadable C++ or C code. I am using some
very well known and well proven library like STL, Boost and Blitz.
Gavin Deane
I totally agree with your point, in a normal environnement, but he's
working for small devices, therefore it's not only a matter of
Optimization, but more a matter of good practices for those targeted
platforms.
I don't do optimization, not perform any treak to optimize a code,
other than writing some template specialization. Only I want to assist
compiler to optimize my code. And to the requirement of the program,
and target platform this assistance change (It is much profile guided
optimization). I am using GCC, and target is a StrongARM processor
(Intel XScale). memory is as little as 50-200K.
May be C is a better choice, but from design point I needed to use
standard C++ (as it is going to be a scale down version of C++ program
written for PC ) , and in my experience, C++ is doing better job of
parallization of code or copying memory at a chunk.
The main difference is, for this small processors, one have to be
extremely carefull about memory allocation (or in that matter any
memory related operations). It is better to keep them at the bottom
level. while simple instructions are reasonably faster.And caching
effect is very dominant in those processors. Thus the thumb rule most
of the time becomes, pre-allocate some memory and use them, rather than
create memory and delete memory. We use a specially designed container
(circular_buffe r ) for most purpose which is a deque but have reserve
facility like vector, little more flexible than boost::circular _buffer.
So mainly placement new comes a better choce (allocator class).
However GCC really helps me for all of these optimizations.
I am looking at
https://sourceforge.net/projects/smart-pointer , and
how they make a faster than boost ptr_container. It looks good.
The considerations you make are very valuable though; The best is to
test both of the scenarios, see how it's managed in your targeted
device, and then sticking to one or another; Tell me if you agree :)
Thanks to all for these valuable discussions.
Cheers,
K