[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [rtl] Crashing when deleting C++ objects!
I think I understand this problem, and will explain it.
Someone please correct me if I'm wrong.
I am using a pointer to a base class to hold the child class.
When I call a virtual function on this object, the compiler recognises that
the object is really an instance of the child class, and calls the method
defined in the child class (run-time binding).
This is the principle of polymorphism, and it works fine for my class
methods.
The same should apply to the destructor. I have defined this as virtual, so
the child destructor should be called when delete is invoked.
I believe that the delete operator defined in rtl_cpp.h cannot handle
run-time binding, and locks-up. Perhaps a more sophisticated function is
needed.
If I'm correct, this is a limitation, which should be removed at some point.
I can live with it, as I'm not intending to dynamically allocate and
deallocate to a great extent during run-time. I just won't delete these
objects so rmmod doesn't lock-up the system. Sure, I'll have a memory leak,
but what the hey.
David
-----Original Message-----
From: David Olofson [mailto:david.olofson@reologica.se]
Sent: 15 October 2001 16:15
To: rtl@fsmlabs.com
Subject: Re: [rtl] Crashing when deleting C++ objects!
On Monday 15 October 2001 12:59, David Hamilton wrote:
> Hmmm!
> I've got a simple C++ program running under rtlinux. When I stop it
> with rmmod, my systems locks up. I've narrowed this down to a delete
> call in one of my destructors. Actually this is my only delete call
> executed in a thread
That's probably exactly why it locks up.
> (deletes called directly from cleanup_module work
> ok).
> There is nothing wrong with the code (it will fail even if the object
> destructors do nothing).
> Perhaps, I'm not linking correctly with the definitions of new and
> delete included in the rtl_cpp.h file!?
>
> Which brings me to a question. Why do the new and delete functions have
> to be declared at all? Aren't they part of the C++ programming
> language.
Yes, but they are still operators, which must be implemented. This is
usually done in some standard library (normally using malloc() and
free()), but 1) as you're building a module (a kind of shared library),
you never link with a standard C++ library, and 2), even if you *did*
link that library in, it wouldn't load into kernel space, as there are no
malloc() or free() functions in there.
> Are the standard C++ versions unacceptable to RTLinux?
> Perhaps my code is linking to the normal C++ definitions of new and
> delete and that is why the system crashes.
No. The module would refuse to load due to unresolved symbols.
//David Olofson --- Programmer, Reologica Instruments AB
.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
`----------------------------> http://www.linuxdj.com/maia -'
.- David Olofson -------------------------------------------.
| Audio Hacker - Open Source Advocate - Singer - Songwriter |
`-------------------------------------> http://olofson.net -'
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail majordomo@rtlinux.org OR
echo "unsubscribe rtl <Your_email>" | mail majordomo@rtlinux.org
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/