C or C++?
Steven W. Orr
steveo at syslang.net
Mon May 30 11:42:00 EDT 2005
On Monday, May 30th 2005 at 09:35 -0400, quoth Bill Freeman:
=>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.
I am not a c++ wiz, but I always thought that that was a fundamental
problem. How do you create a class that doesn't always call new if you
know that the lifetime of the storage would be appropriate for the stack
in certain cases?
--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
More information about the gnhlug-discuss
mailing list