473,796 Members | 2,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ STL in embedded systems

Are there any restrictions/problems for use of C++ STL in development
in embedded systems?
In particular:
* Does STL require too much space/memory?
* Is 'implementation of STL algorithms/methods' reenterable/reentrant?
* What is the cost to provide continuity of vectors in memory?
Any other problems?

--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

Jan 3 '06
49 8975
Alex Vinokur wrote:
Are there any restrictions/problems for use of C++ STL in development
in embedded systems?
In particular:
* Does STL require too much space/memory?
* Is 'implementation of STL algorithms/methods' reenterable/reentrant?
* What is the cost to provide continuity of vectors in memory?
Any other problems?


One thing to note here, you might not be able to use a particular
standard library implementation, but you can certainly use the STL
concepts. As long as you have some class that models the concepts in
STL, you should be able to use many of the standard library algorithms
without any problems.

I think the major overhead comes from iostreams, locales etc.

Hope this helps,
-shez-

Jan 4 '06 #11
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alex Vinokur wrote:
Are there any restrictions/problems for use of C++ STL in development
in embedded systems?
In particular:
* Does STL require too much space/memory?
* Is 'implementation of STL algorithms/methods' reenterable/reentrant?
* What is the cost to provide continuity of vectors in memory?
Any other problems?

In the any category, the main criticism for using a straight C++ lib,
let alone STL, is that the stock new() is non-deterministic. I hear tho
that there are certain embedded C++ tool chains which might have some
methods of getting around this. At least, in the early 90's I remember
Chrysler getting into one for one of its auto controllers.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFDu0FwpxC QXwV2bJARAsm+AJ 0c3bCEdHDsiKzEh M6AEk3PIBYtvACe NRTa
jB2W3uidBsbZsns ViEz7eB0=
=bBVe
-----END PGP SIGNATURE-----
Jan 4 '06 #12

Victor Bazarov wrote:
Alex Vinokur wrote:
[...]
Let v be of vector<in> type.
For instance, at the moment v.size() = 10000.
What's v.capacity() ?
Now we do the following thing:
for (int i; i < 20000; i++) v.push_back(i);

Must 'v' be reallocated/copied to provide its continuity for v.size()
== 30000.


Unknown. Depends on the capacity.


Is the capacity is too big, will 'v' be reallocated/copied?
P.S. By the way, does similar continuity problem exist for ordinary
array?


Ordinary array has a fixed size, and no 'push_back' member function, so,
no, such problem does not exist there.

[snip]

I meant use of 'realloc'.

Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

Jan 4 '06 #13
Alex Vinokur wrote:
Victor Bazarov wrote:
Alex Vinokur wrote:
[...]
Let v be of vector<in> type.
For instance, at the moment v.size() = 10000.


What's v.capacity() ?
Now we do the following thing:
for (int i; i < 20000; i++) v.push_back(i);

Must 'v' be reallocated/copied to provide its continuity for
v.size() == 30000.


Unknown. Depends on the capacity.


Is the capacity is too big, will 'v' be reallocated/copied?


I would rather use the words "large enough" instead of "too big", but
if what you meant was "if the capacity is larger than 30000", then no
reallocation would be necessary.
P.S. By the way, does similar continuity problem exist for ordinary
array?


Ordinary array has a fixed size, and no 'push_back' member function,
so, no, such problem does not exist there.

[snip]

I meant use of 'realloc'.


I don't understand this statement. Use of 'realloc' for what?
'realloc' allocates another object and copies the contents. It is
a _deliberate_ action. There is no automatic growing of arrays.

And, according to the Standard, 'realloc' returns a pointer to
a _new_ object (array), whereas the original one is deallocated.
There is no analogy with 'std::vector' whatsoever. But do look
at an implementation of one.

V
Jan 4 '06 #14
In comp.arch.embed ded Alex Colvin <al***@theworld .com> wrote:
The result seems to be that C++ has become unstable.


Whaddayamean, "become"? From where I sit, C++ feels like it has been
a moving target ever since its invention. Its defining standards
change faster than the implementations . Each time the implementors
finally seem to be catching up, the goal is moved.

--
Hans-Bernhard Broeker (br*****@physik .rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
Jan 4 '06 #15

Victor Bazarov wrote:

[snip]
'realloc' allocates another object and copies the contents. It is
a _deliberate_ action. There is no automatic growing of arrays.

And, according to the Standard, 'realloc' returns a pointer to
a _new_ object (array), whereas the original one is deallocated.
There is no analogy with 'std::vector' whatsoever.


How is 'continuity of vectors in memory' provided? Without using
reallocation/deallocation?

[snip]

Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

Jan 4 '06 #16
Alex Vinokur wrote:
'realloc' allocates another object and copies the contents. It is
a _deliberate_ action. There is no automatic growing of arrays.


How is 'continuity of vectors in memory' provided? Without using
reallocation/deallocation?

"automatica lly" :)

Seriously though, the way vectors grow is just an implementation detail
- different implementations will do it differently - only the semantics
are consistent across implementations .

In your case, if you *do* care about the way it is implemented, then I
would suggest try to find (if possible) a standard library
implementation that's intended to be used in an embedded system. Or
you also might find more convenient to use a custom allocator if you
have memory constraints (be aware of type incompatibiliti es though,
with the existing C++ standard). If you have other constraints (apart
from memory constraints) then roll out your own "vector", implemented
with whatever contraints you have.
Hope this helps,
-shez-

Jan 4 '06 #17
Alex Colvin wrote:
>> Are there any restrictions/problems for use of C++ STL in development
>> in embedded systems?

You might want to think about exception handling.[snip]

Good point. On some of my embedded projects, the compiler didn't
support exceptions at all, and so, neither did the STL. Of course, such
an implementation is not fully conformant to the standard, but it was
still very useful. And some parts of the STL don't throw exceptions
anyway (e.g., std::auto_ptr, many algorithms).


I'm with the Embedded C++ folks <http://www.caravan.net/ec2plus/> on this.
I think that the minimum "contract" for a method call is that it return.
But your needs may differ.


It depends entirely on the needs of the particular embedded systems.
Some of today's embedded systems use yesterday's desktop processors,
and consequently, they often have more memory available, have compiler
and standard library with relatively good conformance to the C++03
Standard, and are less susceptible to the kind of problems that the OP
was concerned about.

On the other hand, I have successfully used a subset of the STL
(including std::vector) on an embedded system that has stricter
requirements than "high-end" embedded applications. The compiler for
that system doesn't support exceptions or some other C++ features
(yet), but otherwise, it is fairly good as far as conformance.
As to conformance, I don't know that I've run across a fully conformant
compiler/runtime yet.
No fully conformant compiler cum library exists, though some are close
and are available on a wide variety of platforms (GNU, Comeau, etc.).
But things are getting better IMHO, and many of the remaining
non-conformancies are in areas of the Standard that are not as useful
as they first appeared (e.g., the export keyword).

In any case, I write object-oriented C++ code that uses the STL that is
buildable on several different embedded platforms with different
compilers, and I use a commercial lint tool that helps maximize the
portability (as well as check for errors). The bottom line for me is
that, while C++ compilers and libraries are not fully conformant, they
are conformant enough for my needs (and I suspect for many other
programmers' needs).
As implementations like GCC approach conformance,
their libraries have to keep changing.
Can you give an example? The library implementations might be refined
or tweaked behind the scenes, but the interfaces should generally be
stable.
The result seems to be that C++ has become unstable. You can't link
against a library unless you're using the same compiler version. It's best
if you have all the libraries in source.


I'm not sure what you mean here. I don't think you mean that different
compilers generate different object file formats or that they use
different calling conventions since these problems would apply equally
to any language, but are you referring to the fact that, e.g., a
library function might throw an exception but your compiler doesn't
support exceptions? Please clarify.

Cheers! --M

Jan 4 '06 #18
Alex Vinokur wrote:
Victor Bazarov wrote:

[snip]
'realloc' allocates another object and copies the contents. It is
a _deliberate_ action. There is no automatic growing of arrays.

And, according to the Standard, 'realloc' returns a pointer to
a _new_ object (array), whereas the original one is deallocated.
There is no analogy with 'std::vector' whatsoever.


How is 'continuity of vectors in memory' provided? Without using
reallocation/deallocation?


std::vector does sometimes use the allocated-copy-destroy mechanism
while it is growing (see my other post for more details). std::realloc
does a similar thing with malloc'ed memory and POD types when the size
passed to std::realloc is larger than the current size. The difference
is that std::vector works on non-POD types as well.

You might be interested in these articles by Andrei Alexandrescu:

http://www.cuj.com/documents/s=7992/...r/alexandr.htm
http://www.cuj.com/documents/s=7990/...r/alexandr.htm
http://www.cuj.com/documents/s=7988/...r/alexandr.htm

They describe generic typed buffers, which are somewhere in between
built-in arrays (which are evil; see the FAQ) and std::vector, which
may not have acceptable performance for certain applications. The third
discusses realloc and growing in gory detail.

Cheers! --M

Jan 4 '06 #19
On 3 Jan 2006 10:47:05 -0800, "Alex Vinokur"
<al****@users.s ourceforge.net> wrote:
Are there any restrictions/problems for use of C++ STL in development
in embedded systems?


Hey look what I just found, from their website:

The Dinkum EC++ Library as specified by the Embedded C++ Technical
Committee. (See the Dinkum EC++ Library.) This is far and away the
most widely used EC++ library in the embedded programming community.

http://www.dinkumware.com/libdual_vc.html

Good Luck.

Not all those who wander are lost. - J.R.R. Tolkien
Jan 4 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
3104
by: Brandon | last post by:
Java seems to have taken off as the platform and language of choice for many embedded devices. Would it be feasible for Python(perhaps running on an embedded version of Linux) to act in such a capacity. Most of my experience with Python has been with Unix-type scripting tasks and using it when it is an applications built in scripting, but I know some people try to use to build larger complex applications. Is the Python interpreter portable...
12
2984
by: Bill Hanna | last post by:
C is inadequate for embedded systems for the following reasons: 1) Direct addressing of memory mapped I/O is not supported simply and easily. You have to find work-arounds that are compiler dependent. You have to create macros , use casting and use indirect addressing (pointers) to read or write to memory mapped I/O. 2) C does not support real time interrupts. The interrupt vectoring is compiler dependent.
10
2521
by: Alex Vinokur | last post by:
The memory allocation issue in embedded systems is usually critical.. How can one manage that? 1. Via 'new' char* p = new (nothrow) char ; if (p == 0) { // He we know that it is impossible to allocate the requested memory // We can do something relevant.
20
22544
by: Jack | last post by:
Is there a Python packaging that is specifically for embedded systems? ie, very small and configurable so the user gets to select what modules to install? For Linux-based embedded systems in particular? I'm thinking of running it on the Linksys's Linux-based open source router WRT54G. It has 4MB flash and 16MB RAM. I think another model has 16MB flash. Any possibilities of running Python on these systems?
0
2271
by: YellowFin Announcements | last post by:
Whitepaper: "Yellowfin Reporting" enables Embedded Business Intelligence -------------------------------------------------------------------------------- Embedded reports are a standard requirement of most applications. But users are increasingly demanding more sophisticated reporting from applications - seeking such features as custom report design, ad hoc report creation and analytics. Developers that want to embed business...
2
1311
by: pdeivanayagam | last post by:
hi i hav cmpltd my engg.i am thnkng of doing an embedded systems. course...can i knw abt prospect of embedded systems?wut will be the oppurtunities available in embedded systems?i want some infm reg this.can anyone guide me reg this? regards deivanayagam
14
1898
by: Martin Wells | last post by:
When I want to store a number, I use "unsigned". I go with unsigned because it's the natural type for the system, and so should be the fastest. However, there are 8-Bit microcontrollers out there that do 8-Bit arithmetic faster than 16-Bit arithmetic, and so on these systems char is faster than int. Standarising C in such a way that int is at least 16-Bit, has this made C both slow and memory-hungry for embedded systems programming?
20
2055
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
There are a few guarantees I exploit in the C Standard. For instance, I might write (unsigned)-1 to get the maximum value for an unsigned integer. Also, I might rely on things such as: memset(data,-1,sizeof data)
30
4303
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
Let's say we had a simple function for returning the amount of days in a month: unsigned DaysInMonth(unsigned const month) { switch (month) { case 8: case 3: case 5:
0
9525
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10452
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10221
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10169
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.