Re: C++/CLI Unions and Garbage collection
- From: "Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@xxxxxxxxxxxxxxx>
- Date: Thu, 19 Jan 2006 22:13:43 -0800
minorguy wrote:
> Then I use these structures from C# and write the following:
>
> MyUnion mu = new MyUnion();
> mu.one = new One();
> mu.two = new Two(); // is the instance of class One now available
> for GC?
> mu.two.a = 42;
>
> Has the memory allocated for One now been made available for garbage
> collection?
Yes.
> Obviousy it would in the typical case when One^ and Two^ don't
> overlap. But what if they do? Does the garbage collector still track
> this?
> ------------------------------------
>
> 2.) For my second question: is it known what the size of a reference
> handle is?
> For example, if I were to instead write MyUnion as:
>
> [StructLayout(LayoutKind::Explicit)]
> public ref struct MyUnion
> {
> [FieldOffset(0)] One^ one;
> [FieldOffset(4)] Two^ two; // <--- note different field
> offset };
>
> Am I allowed to depend on One^ taking up four bytes?
No. The size of a reference is (I believe) undefined. It's certainly not 4
bytes on a 64-bit CLR.
-cd
.
- Follow-Ups:
- Re: C++/CLI Unions and Garbage collection
- From: minorguy
- Re: C++/CLI Unions and Garbage collection
- References:
- C++/CLI Unions and Garbage collection
- From: minorguy
- C++/CLI Unions and Garbage collection
- Prev by Date: Re: how to know an int is the member of an enum type?(C++/CLI)
- Next by Date: Re: Using /clr:safe and Native Types
- Previous by thread: C++/CLI Unions and Garbage collection
- Next by thread: Re: C++/CLI Unions and Garbage collection
- Index(es):