C or C++?

Bill Freeman f at ke1g.mv.com
Mon May 30 09:35:01 EDT 2005


Chris writes:
 > You should never use C++ in a real-time situation, simply becasue the 
 > constructors and destructors will be continually allocating memory, 
 > which is completely non-deterministic. A real-time system needs to be 
 > deterministic.

	Allocation and deallocation is actually under your control,
and can be no more burden than in C.  For example, an local variable
that is an instance gets created on the stack, just like a C structure
that is a local variable.  The class itself might have pointers to
objects that you allocate inside the constructor, but, again, that is
under your control - if you are the author of the class.  You can also
override new and delete to allocate from a fast pool, pre-allocating
your high water mark usage of a class, and making
allocation/deallocation deterministic for that class.  You would do a
similar thing for C structures used in the same way.

	However, what you say is undoubtedly true of many of the classes
in the standard library.  And if you're not going to use them, then the
case for using C++ gets weaker.

							Bill



More information about the gnhlug-discuss mailing list