C++ STL in embedded systems - Page 2

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Re: C++ STL in embedded systems
Quoted text here. Click to load it
...

If you need an ordered associative container that doesn't require
elements to be copied into a general-purpose heap, consider:

http://www.geocities.com/wkaras/gen_cpp/avl_tree.html

At the other end of the spectrum, if your embedded system runs Linux
(or some other OS with per-process memory protection and explicit
shared memory), and you need to create an STL Allocator for shared
memory, this code (in straight C) may be a useful starting point:

http://www.geocities.com/wkaras/heapmm/heapmm.html

All of the above code is designed to be reentrant.


Re: C++ STL in embedded systems

Quoted text here. Click to load it
...

Here is a link to the slides for a 1999 presentation by Bjarne
Stroustrup about
using Standard C++ including the STL in embedded systems.

http://public.research.att.com/~bs/esc99.html


Re: C++ STL in embedded systems
With regard to the number below:

Read, sort, and write floating-point numbers

        unoptimized            optimized

elements    C++    C    C/C++ ratio    C++    C    C/C++ ratio

500,000        3.5    6.1    1.74        2.5    5.1    2.04
5,000,000    38.4    172.6    4.49        27.4    126.6    4.62


One of things I find interesting about the source - he used is his
comment:

buf.reserve(res);    // logically redundant; for efficiency only

How is that 'logically redundant'.  If you _dont_ call reserve.  You'll
end up with a host of re-locations and the C++ numbers will be alot
worse.   Am I missing something?


Re: C++ STL in embedded systems

Quoted text here. Click to load it

std::vector::reserve() only functions to speed things up; it doesn't
have an effect on the result of the program. Likewise, I might do this:

 void Increment1( int& i )
 {
   const volatile n = 10;
   i += n;
   i -= (n-1);
 }

 void Increment2( int& i )
 {
   ++i;
 }

These two are logically equivalent (i.e., they do the same thing), but
the second is almost certainly more efficient.

Cheers! --M


Re: C++ STL in embedded systems
Quoted text here. Click to load it

Oops. That should have an "int" thrown in there.


Re: C++ STL in embedded systems
|| std::vector::reserve() only functions to speed things up; it doesn't

|| have an effect on the result of the program.
There to speed things up but doesn't affect the result of the program!!
  Not just bear with me.  You're saying that if I opt not use reserve
the end result (i.e the benchmarks) would be the same?

're-location' is a constant 'concern/gripe' when viewed from - what
seemingly is the most popular container.  i.e the Vector.  INMHO, it's
a much ado about nothing if you have a member function like reserve.
That said, if you opt _not_ to reserve, you're faced with the
copy/destroy/re-create saga.  With your example  'benchmarks' will be -
for the most part - comparable.  I'm not seeing how the benchmarks will
be comparable if he chose to call reserve ahead of time.

Time to pull out the compiler :)


Re: C++ STL in embedded systems
Quoted text here. Click to load it
[snip]

No, I'm saying the sorted output of the program would be identical.
Quoted text here. Click to load it
Increment1() and Increment2() are identical in function (i.e. logically
the same) but different in implementation, which translates to speed of
execution for our current context.

Cheers! --M


Re: C++ STL in embedded systems
Quoted text here. Click to load it

No, but the *output of the program* would be the same.  That's what was
meant by "logically redundant"; i.e. the difference is a *practical*
one, not a *logical* one.

--
Mike Smith

Re: C++ STL in embedded systems
Quoted text here. Click to load it

The relocations don't matter from a *logical* standpoint; i.e. from the
standpoint of *what* the program will do when executed.  Sure, it
matters a great deal from a *practical* standpoint, i.e. in terms of
real-world performance, but that's not the same thing.

--
Mike Smith

Re: C++ STL in embedded systems
I did face few issues when introducing STL in a vxWorks based
system.Major problems were:
- significant code bloat
- incomplete STL support by the specific vxWorks version that we were
using. There were scores of linking errors whenSTL was used.Had to make
modifications to the STL header files to make it work.
- no concept of namespace on vxWorks (Everything happened to be in
default namespace)

But probably these issues are specific to vxWorks (and that too to a
particular version of it) and may not hold true for embedded system in
general. But Code bloat was definitely a problem and I found many
resources on Net which confirmed this problem of using STL in embedded
systems.


Re: C++ STL in embedded systems
|| But probably these issues are specific to vxWorks
|| (and that too to a particular version of it) and may not hold
||  true for embedded system in general

How long ago was this?  I'm using vxWorks  (Tornado IDE 2.2.1) - STL
and all.  Doing FFT/IFFTs and Boundary Element Math withough a hitch.

|| But Code bloat was definitely a problem and I found many
|| resources on Net which confirmed this problem of using STL in
embedded
||  systems.
Is this relegated to 'embedded systems'?  Furthermore, how do you
measure this 'code bloat'?   I'm curious.

With all due respect.  I think today (my experience) - this notion of
issues pertaining to STL usage in embedded systems is much ado about
nothing (lots of smoke and mirrors).  My _real_ problem, is being stuck
with gcc 2.96.  Beyond that. I've had no issues.  Of course I haven't
measured code bloat yet but we'll see.


Re: C++ STL in embedded systems
Quoted text here. Click to load it
...

It would be nice if there were alternative implementations of the
containers (especially map/set) where most of the code was non-
templated and used void * and function pointers heavily.  The
templates would just be a type-safe veneer.  Seems like this
approach would be a little less fast but could greatly reduce
bloat (in those bloat-sensitive situations).

Has anyone tried this?


Re: C++ STL in embedded systems
Quoted text here. Click to load it
[snip]

In general, you can't give a simple answer to such questions.
The specifics of how your particular embedded system works
are going to, in the extreme cases for various features, be the
choke point.

Consider a case where, for hardware reasons, you needed to
limit the amount of RAM on your system to the absolute
smallest possible amount. Anything that produced an extra
temp variable, an extra chunk of something shoved on the
stack, etc. etc., would be hard to accomodate. In such a case,
it might be easier to get your job done in some other language
than C++. Possibly assembler, for example. Though as time
goes by, the amount of RAM available on most hardware is
increasing. I recall a project from many years ago where
an industrial monitor (radiation hand and foot checker) had
a very small amount of RAM, like 128 bytes or some silly
small number. Trying to fit a C++ prog into such hardware
would have been tiresome. RAM is much cheaper these days.
The latest version of this device has a huge whack of RAM.

Other considerations: Suppose the system cannot require
human intervention, or human intervention is expensive in
some way. In such a case, a "bullet proof" implementation
that won't crash, won't leak resources, etc., is going to be
a big concern. A good implementation of the STL will look
pretty good in such cases, as compared to a roll-your-own
set of containers. So will reading the series of books
"Effective C++", "More Effective C++", and "Effective STL"
(though I may have munged the titles).

There are many other possible concerns. For example:
You need a compiler that outputs optimized code for
your hardware. This is crucial above all else. If the code
won't run on your hardware, there's no point worrying
about what library to use. So, if your compiler has limits
(not unusual in the case of hardware specific compilers,
though getting better) you should start with your list of
possible compilers, and figure out what is possible from
that. If the only compiler available is an older non-compliant
one, you may have trouble getting a good STL implementation
to work on it. I recall another project from many years ago
where the only compiler that would output code for the
hardware was a C compiler. And an old (1988 or so) C compiler
at that. Tiresome.

What other libraries are required for the project? If it's
a specific chunk of hardware, chances are there is an
API kit provided by the manufacturer. The advantages of
using such a kit may outweigh the advantages of using
the STL, supposing you can't use both. Though, again,
as time goes by most hardware makers are supporting
the STL, and more modern implementations of it.

There are many other possible considerations. For
example, if you explore these issues, the client might
be convinced that the extra RAM might be worth it in
order to be able to shorten the development time. Or
to be able to do the development in C++ rather than
assembler, and so be able to provide lots of new
sexy features in the same development time.
Socks


Re: C++ STL in embedded systems
Quoted text here. Click to load it

If you are wondering about microsoft's evc++ 4.0 and above, the simple
answer is, they don't provide one due to yada yada reasons. Every
platform has its own library, and their MFC has a memory leak. You can
possibly get sources for the STL and compile them with each library for
each platform that you are working for. But it is not clear if evc++ is
truly standards conforming.

Quoted text here. Click to load it


Re: C++ STL in embedded systems

Quoted text here. Click to load it

If by STL you really mean the Standard Template Library, then most
versions of eVC++ contain pretty complete implementations. (Ours, of
course.) What Microsoft has managed to do, for mysterious (yada
yada?) reasons, is butcher the combined C/C++ library in bizarre and
inventively different ways for each release of eVC++. We have a tidy
side business replacing the missing bits for those who need better
code portability between desktop and embedded versions of the same
compiler family.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com



Site Timeline