Will Miles
|
Re: Using C++ in a hard real-time system
|
Will Miles
09/15/2008 10:10 AM
post13411
|
Re: Using C++ in a hard real-time system
We also use C++ for our data acquisition system, including some real-time instrument control loops. Andy's pretty much
said it all - there aren't any real gotchas other than keeping an eye out for implicit memory allocation on critical
paths.
|
|
|
Rennie Allen
|
Re: Using C++ in a hard real-time system
|
Rennie Allen
09/15/2008 1:07 PM
post13433
|
Re: Using C++ in a hard real-time system
> additional pointer call in terms of penalty. Probably the worst C++ issue
> for real-time is rampant use of "new/delete" in some code. The allocator
> doesn't have a fixed-time execution.
Characterizing new/delete as a problem in C++ (when comparing to 'C' at least) is somewhat disingenuous, since C++
provides far better facilities to the developer than 'C' does. Due to overloading, C++ allows a custom allocator/
deallocator to be transparently invoked on any new/delete. A 'C' developer would need to create a cover function to
handle this (no trivial feat if there is much legacy code base to deal with).
A well designed hard real-time system in C++ would have the static factory class pre-allocate instance aligned memory
for all the instances that it is capable of manufacturing when the factory class is instantiated (i.e. at init time),
and the factory class header would publish overloaded new/delete operators for each class (that would instantiate the
objects into this pre-allocated, and aligned memory).
Alternatively, each class can provide its own new/delete, but must either do the "pre-allocation" on first instantiation
, or require that the client code do the pre-allocation, and provide an allocator callback (which is quite awkward).
|
|
|