C++ STL ARM - Page 1
Forum section: electronics / general

author: diyaudio
author_rank: Frequent Contributor
timestamp: February 06, 2017, 10:05:42 am
content: How much of the STL library is available for ARM GC? compared to C routines how is the efficiency for say a STMF4 microcontroller, I want to start using a mix of C and C++ for some of my modules to test the waters to get a better understanding of C++ for resource sensitive applications i.e limited flash size, stack memory.

author: janoc
author_rank: Super Contributor
timestamp: February 06, 2017, 10:16:04 am
content: Hum, not quite sure what are you asking.At least for GCC there is the entire STL available for ARM. It is a well supported platform. Of course, on a micro you likely won't have stuff like threading unless you use an RTOS and a port of STL that supports it.Re efficiency - depends on your code, your compiler and the microcontroller you are compiling for. If you know what you are doing, C++ can be comparable with C code, even when using STL.However, if you don't know what you are doing, you are very likely to write a code that won't fit in your target micro ... STL is not the easiest thing to use on an embedded system for this reason - you will most likely need to write your custom allocators and things like that.

author: Jeroen3
author_rank: Super Contributor
timestamp: February 06, 2017, 06:05:05 pm
content: Most of the stuff is just memory management. Vectors, maps, not much you can do wrong there apart from using more RAM. Because the types are multipurpose they will use more RAM for settings.Things that do create problems are the hash and bit stuff. Here there could be hardware features available. Such as an sha module or bitbanding.

author: janoc
author_rank: Super Contributor
timestamp: February 07, 2017, 09:27:50 am
content: The memory management can be an enormous problem on a small micro where you have something like 2-20kB of RAM. The default STL allocators are not appropriate to use in such situation, for all sorts of reasons (allocation overheads, memory fragmentation, easy to blow the stack if you attempt to allocate something too large, etc.)Other problems are potential non-determinism - e.g. adding an element to an vector can take very different amount of time depending on whether the element is simply added to preallocated space or the vector needs to be reallocated first and then copied. That is usually not a problem on a desktop, but can be very problematic on a micro, depending on situation.You may want to look at these too:http://www.etlcpp.com/http://www.embedded.com/design/programming-languages-and-tools/4429790/How-to-make-C--more-real-time-friendlyhttp://www.embedded.com/electronics-blogs/programming-pointers/4027626/Preventing-dynamic-allocation

author: westfw
author_rank: Super Contributor
timestamp: February 07, 2017, 10:25:38 am
content: QuoteI feel like I need to point out that if you're using a *BIG* ARM chip, like a linux, android, or IOS system, then of course you have a run-time environment with all of the standard STL available.The Microcontroller ARMs suffer from the "RAM poor" nature of microcontrollers, as others have mentioned. Whether you can get away with real STL, some sort of customized STL, or no STL at all, depends on the exact circumstances.

author: Koen
author_rank: Frequent Contributor
timestamp: February 07, 2017, 10:59:00 am
content: Have a look at EASTL.

author: legacy
author_rank: Super Contributor
timestamp: February 07, 2017, 12:26:01 pm
content: I have for sale a few ARM SBC boards, capable of running linux, or ucOS/2