You are here: Home / RTLWS 1999-2017 / RTLWS Submitted Papers / 
2022-08-13 - 06:15

Real Time Linux Workshops

1999 - 2000 - 2001 - 2002 - 2003 - 2004 - 2005 - 2006 - 2007 - 2008 - 2009 - 2010 - 2011 - 2012 - 2013 - 2014 - 2015

13th Real-Time Linux Workshop from October 20 to 22 at the Faculty of Electrical Engineering, Czech Technical University in Prague

Announcement - Hotels - Directions - Agenda - Paper Abstracts - Presentations - Registration - Abstract Submission - Sponsoring - Gallery

Dynamic memory allocation on real-time Linux

Jianping Shen, Institut Dr. Foerster GmbH und Co. KG
Michael Hamal, Institut Dr. Foerster GmbH und Co. KG

Deterministic and automatic memory management in a multi-threading environment

Dynamic memory allocation is present in many real-time systems. In such systems we have some data types, which are referenced by different threads. Their numbers and their lifetime are unpredictable. They must be dynamically allocated on the heap. In a real time system, the allocation must be deterministic. Dynamic memory management on real time multi-threaded systems has two handicaps.

  1. Execution time for memory allocation/deallocation should be short and predictable. Heap allocation is not deterministic. Because of fragmentation and some other reasons the execution time of a heap allocation is not predictable.
  2. For objects which are referenced by more than one thread, it is difficult or even impossible to predict which thread will be the last user of the object and has the duty to deallocate the object's memory at the right time.

In such systems we need a deterministic, automatic and multi-threading suitable dynamic memory management solution for C and C++ real-time development. In our project, we find an approach, which combines a shared pointer and a cooperative memory pool.

  • The memory pool provides memory allocation with constant execution time.
  • The shared pointer frees all allocated memory - correctly (at the right time) and automatically.

A shared pointer keeps track of the number of users of the dynamic allocated object. If the last user thread finished its work with the object, the shared pointer automatically deallocates the object. In our case the object returns to the memory pool.

The standard shared pointer “std::shared_ptr“ allocates heap memory on run time for its reference count, therefore cannot be directly used in real-time systems. We modify the standard shared pointer, make it use preallocated reference counts instead of dynamic allocated reference counts. Our memory pool is extended correspondingly. It preallocates the memory not only for the object but also for its related reference count. With support of the memory pool the modified shared pointer works completely without heap allocation on run time.

Using the above described approach we provide in this paper a generic solution, which meets both: high system reliability by automatic memory deallocation and deterministic execution time by avoiding heap operations. It is a new general memory management solution for all real-time developers.