Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using boost in embedded system with memory limitation

We are using c++ to develop an application that runs in Windows CE 4 on an embedded system.

One of our constraint is that all the memory used by the application shall be allocated during startup only. We wrote a lot of containers and algorithms that are using only preallocated memory instead of allocating new one.

Do you think it is possible for us to use the boost libraries instead of our own containers in these conditions?

Any comments and/or advice are welcomed!

Thanks a lot,

Nic

like image 897
Nicolas Avatar asked Oct 03 '08 12:10

Nicolas


People also ask

Is boost library still useful?

After 20 years of active Boost development, it's now recognized as a very powerful C++ library, for each major version many C++ libraries from the community were added. The Boost reviewers have an advanced C++ skills and their contributions guarantee a high quality for many years.

Do embedded systems need memory?

Engineers use non-volatile memory in embedded systems to store code and other data that the device always needs, including after the system restarts.

What is embedded memory?

At a basic level, embedded memory contains volatile or non-volatile hardware components. Volatile storage is made of temporary storage spaces, while non-volatile consists of persistent storage.


3 Answers

We use boost for embedded systems. With boost you can pick and choose what you use. We use smart_ptr and boost::bind in all of our projects. We write software for cheap cell phones. And if Windows CE can run on your hardware I would expect that parts of boost would be applicable. There are parts of boost that have no allocation and you might find them useful.

I would pick and choose based on your requirements.

Like anything that you use, you need to know the costs.

like image 68
Ted Avatar answered Oct 17 '22 12:10

Ted


You could write your own allocator for the container, which allocates from a fixed size static buffer. Depending on the usage patterns of the container the allocator could be as simple as incrementing a pointer (e.g. when you only insert stuff into the container once at app startup, and don't continuously add/remove elements.)

like image 39
Tobi Avatar answered Oct 17 '22 14:10

Tobi


Replacing your containers with Boost containers is NOT a good idea. The work to make appropriate custom allocators wouldn't be that bad, but you'd be violating the spirit of your 'allocate at startup' rule. The idea behind this rule (in my experience) is generally to make sure that you don't have to deal with out of memory type situations at run-time. The idea is to make sure that you have all the memory you could possibly need RIGHT AT THE START, so that there's no possibility of any part of the system coming up short of memory later on.

If you used the Boost containers with a custom allocator, you'd suddenly have to deal with the possibility that the pool the container is allocating from could go empty, thus eliminating the purpose of the 'allocate at startup' rule.

In the situation of a limited memory device, I would avoid any kind of container more complex than a statically allocated array.

like image 22
Michael Kohne Avatar answered Oct 17 '22 12:10

Michael Kohne