GC and multiple inheritance as in C++

View: New views
5 Messages — Rating Filter:   Alert me  

GC and multiple inheritance as in C++

by Juro Jon () :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello, I have a question concerning implementation of multiple inheritance in CIL. For a C++ MI object, a pointer can points to inside the object body instead of the its head. eg.
struct A : B, C { };  C* c = new A;
While Boehm GC detects this kind of reference, is it a supported feature of Mono? If not, what is the suggested way to implement it (eg. what is the C++/CLI way) ?

Thanks you

Re: GC and multiple inheritance as in C++

by David Jeske :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

AFAIK, you don't need C++ MI to have a pointer to something inside an object
body. This can happen if you take a ref of any instance data in C#.

http://www.java2s.com/Code/CSharp/Language-Basics/CRefandOutParameters.htm

-- Juro Jon wrote:
> Hello, I have a question concerning implementation of multiple inheritance in
> CIL. For a C++ MI object, a pointer can points to inside the object body
> instead of the its head. eg.
> struct A : B, C { };  C* c = new A;
> While Boehm GC detects this kind of reference, is it a supported feature of
> Mono? If not, what is the suggested way to implement it (eg. what is the
> C++/CLI way) ?
_______________________________________________
Mono-gc-list maillist  -  Mono-gc-list@...
http://lists.ximian.com/mailman/listinfo/mono-gc-list

Re: GC and multiple inheritance as in C++

by Juro Jon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I don't know much of CLI specification so I may be missing something trivial. Java GC assumes that all pointers point to some "header" to identity the memory object. Since Java is single inheritance a pointer always points to the head of a full object, but for C++ multiple inheritance it may be pointing to an embedded part and need to be adjusted to find the full object. Are you saying that the CLI GC or typesystem has some way to do this adjustment?

Thanks

On Fri, Jun 13, 2008 at 3:50 AM, David Jeske <jeske@...> wrote:
AFAIK, you don't need C++ MI to have a pointer to something inside an object
body. This can happen if you take a ref of any instance data in C#.

http://www.java2s.com/Code/CSharp/Language-Basics/CRefandOutParameters.htm

-- Juro Jon wrote:
> Hello, I have a question concerning implementation of multiple inheritance in
> CIL. For a C++ MI object, a pointer can points to inside the object body
> instead of the its head. eg.
> struct A : B, C { };  C* c = new A;
> While Boehm GC detects this kind of reference, is it a supported feature of
> Mono? If not, what is the suggested way to implement it (eg. what is the
> C++/CLI way) ?


_______________________________________________
Mono-gc-list maillist  -  Mono-gc-list@...
http://lists.ximian.com/mailman/listinfo/mono-gc-list

Re: GC and multiple inheritance as in C++

by David Jeske :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think my optimism may have got the better of me. The CLR has a mechanism to
handle internal references, but I don't believe this answers your question or
solves your issue. The CLI GC handles interior references to objects even in C#
for "byref" paramaters, but only for interior references on the stack. Here are
some potentially useful references:

(see the bottom of this for comments on Rotor)
http://blogs.msdn.com/joelpob/archive/2004/02/26/80776.aspx
http://ksrenevasan.blogspot.com/2005/08/incomplete-rotor-gc-notes.html

Partition I, section 12.4.1.5.2, it talks about byref and lifetimes.
Partition II, section 12, it talks about interfaces and mentions MI.

----

However, it occurs to me that in C++ MI you may need interior pointers that are
not on the stack. Your concern may be well-founded, as the snippets I can find
only talk about Rotor tracing interior references which are on the stack.

Perhaps someone with more knowledge can offer a more complete (or accurate)
answer.

-- Juro Jon wrote:
> I don't know much of CLI specification so I may be missing something
> trivial. Java GC assumes that all pointers point to some "header" to
> identity the memory object. Since Java is single inheritance a pointer
> always points to the head of a full object, but for C++ multiple inheritance
> it may be pointing to an embedded part and need to be adjusted to find the
> full object. Are you saying that the CLI GC or typesystem has some way to do
> this adjustment?
_______________________________________________
Mono-gc-list maillist  -  Mono-gc-list@...
http://lists.ximian.com/mailman/listinfo/mono-gc-list

Re: GC and multiple inheritance as in C++

by Jason Whittington :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

I believe the answer here is: “no”.   MI languages have to find a way to fake it.

 

Microsoft’s C++/CLI fakes it by not allowing MI for managed types.   MI classes are represented as value types in the CLI and thus don’t behave with “true” polymorphism.  They do in the sense that C++ code compiled together works correctly, but to other languages the inheritance is opaque – calling GetType().BaseType will just yield System.ValueType.

 

The CLR port of Eiffel fakes it by using a [somewhat complex and arcane] scheme where inheritance in Eiffel is modeled with interfaces in .NET.

 

Jason

 

 

From: mono-gc-list-bounces@... [mailto:mono-gc-list-bounces@...] On Behalf Of Juro Jon
Sent: Thursday, June 12, 2008 8:36 PM
To: mono-gc-list@...
Subject: Re: [Mono-gc-list] GC and multiple inheritance as in C++

 

I don't know much of CLI specification so I may be missing something trivial. Java GC assumes that all pointers point to some "header" to identity the memory object. Since Java is single inheritance a pointer always points to the head of a full object, but for C++ multiple inheritance it may be pointing to an embedded part and need to be adjusted to find the full object. Are you saying that the CLI GC or typesystem has some way to do this adjustment?

Thanks

On Fri, Jun 13, 2008 at 3:50 AM, David Jeske <jeske@...> wrote:

AFAIK, you don't need C++ MI to have a pointer to something inside an object
body. This can happen if you take a ref of any instance data in C#.

http://www.java2s.com/Code/CSharp/Language-Basics/CRefandOutParameters.htm


-- Juro Jon wrote:
> Hello, I have a question concerning implementation of multiple inheritance in
> CIL. For a C++ MI object, a pointer can points to inside the object body
> instead of the its head. eg.
> struct A : B, C { };  C* c = new A;
> While Boehm GC detects this kind of reference, is it a supported feature of
> Mono? If not, what is the suggested way to implement it (eg. what is the
> C++/CLI way) ?

 


_______________________________________________
Mono-gc-list maillist  -  Mono-gc-list@...
http://lists.ximian.com/mailman/listinfo/mono-gc-list