Does using heap memory (malloc/new) create a non-deterministic program?

In the context of realtime systems, there is more to determinism than a repeatable “execution path”. Another required property is that timing of key events is bounded. In hard realtime systems, an event that occurs outside its allowed time interval (either before the start of that interval, or after the end) represents a system failure.

In this context, usage of dynamic memory allocation can cause non-determinism, particularly if the program has a varying pattern of allocating, deallocating, and reallocating. The timing of allocations, deallocation, and reallocation can vary over time – and therefore making timings for the system as a whole unpredictable.

Leave a Comment