Home

Martin Drautzburg wrote:
> For reasons related to python/swig and garbage collecting I want to
> remember every object in a linked list. I have a common base class
> RCObj which in turn has a static std::list<RCObj*> memory.
>
> My problem is that I cannot get RCObj store the true this pointer.

Why would you need to?

> Even if I pass it explicitly from a derived class (called "Part") as
> in:
>
> Part::Part() {
> this->RCObj::init(this);
>
> the pointer that arrives at RCObj::init() is not the same as "this"
> inside Part::Part()

Of course it isn't. So?

> (gdb) p this
> $4 = (pyramid::Part * const) 0x81b62e0
> (gdb) s
> RCObj::init (this=0x81b6378, that=0x81b6378) at common.cc:65
>
> I assume C++ treats an object as composed of several sections one of
> which is the RCObj section and is silently add an offset (0x81b6378 -
> 0x81b62e0 = 152) to "this" if this shall be treated as an RCObj.
>
> (1) what happens when I "delete this" from within the RCObj scope?

If your destructor is virtual (as it should be), the object is
destroyed correctly and the memory is freed. You shouldn't attempt
to access any non-static members of that object after that point.

> Will it only delete part of the object?

Not if the destructor is virtual.

> (2) how can I possibly keep track of all my created objects?

There are different schemes for that, you should look on the Web
for the available solutions.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

previous
next

Re: Python is overtaking Perl
sqlite3 create table col width?
Re: libgmail failure
Re: Emacs + python
Re: OO book
Podaruj Zycie
Fundacja Iskierka
Kidprotect
Akogo
Pajacyk