Atmapuri said:
Hi!
Yes. It does. All arrays shorter than the limit are allocated inside
the "compactable" part of the GC heap and thus have to be copied
out of the "compactable" heap before they can have a "fixed" address.
Thanks!
Atmapuri
I'd very much like to know where you have this from.
I tried the following code:
Object o = 10;
Debug.WriteLine(o);
GCHandle h = GCHandle.Alloc(o, GCHandleType.Pinned);
Debug.WriteLine(o);
Text = ((Int32)h.AddrOfPinnedObject()).ToString("X8");
h.Free();
// Just for security
GC.KeepAlive(o);
GC.KeepAlive(h);
I then ran this code through the CLR Debugger, and the following code is
the result:
Object o = 10;
00000030 mov ecx,79102290h
00000035 call FFA31CE4
0000003a mov esi,eax
0000003c mov dword ptr [esi+4],0Ah
00000043 mov edi,esi
Debug.WriteLine(o);
00000045 mov ecx,edi
00000047 call 795EAAD8
0000004c nop
GCHandle h = GCHandle.Alloc(o, GCHandleType.Pinned);
0000004d mov ecx,edi
0000004f mov edx,3
00000054 call 78450ABC
00000059 mov esi,eax
0000005b mov dword ptr [ebp-48h],esi
Debug.WriteLine(o);
0000005e mov ecx,edi
00000060 call 795EAAD8
00000065 nop
Text = ((Int32)h.AddrOfPinnedObject()).ToString("X8");
00000066 mov esi,dword ptr [ebp-3Ch]
00000069 lea ecx,[ebp-48h]
0000006c call 7847B8F8
00000071 mov ebx,eax
00000073 mov ecx,ebx
00000075 call 7844DBB8
0000007a mov ebx,eax
0000007c mov dword ptr [ebp-4Ch],ebx
0000007f lea ecx,[ebp-4Ch]
00000082 mov edx,dword ptr ds:[02313048h]
00000088 call 784D4C70
0000008d mov ebx,eax
0000008f mov edx,ebx
00000091 mov ecx,esi
00000093 mov eax,dword ptr [ecx]
00000095 call dword ptr [eax+00000168h]
0000009b nop
h.Free();
0000009c lea ecx,[ebp-48h]
0000009f call 7847BAA8
000000a4 nop
// Just for security
GC.KeepAlive(o);
000000a5 mov ecx,edi
000000a7 call 78FE30D8
000000ac nop
GC.KeepAlive(h);
000000ad mov ecx,79107774h
000000b2 call FFA31CE4
000000b7 mov esi,eax
000000b9 mov eax,dword ptr [ebp-48h]
000000bc mov dword ptr [esi+4],eax
000000bf mov ecx,esi
000000c1 call 78FE30D8
000000c6 nop
As you can see, the magic two lines of code that calls Debug.WriteLine
are the ones at address 45/47, and 5e/60.
When executing the code, from your statement, the value in ecx in the
above two executions of the same code should change, but it doesn't.
It's the same address passed to .WriteLine in both cases.
Additionally, the "Text = " line puts the address as reported by the
GCHandle object into the caption of the form I put this code in, and the
following is what I get during one execution:
ecx : 013ACCEC
text: 013ACCF0
The difference is 4 bytes, which amounts to the VMT pointer or whatever
they call it in .NET (or perhaps something else... or perhaps I'm just
wrong).
As such, it doesn't appear to involve any kind of copying at all, as I
would gather from your statement that the address would then change more.
Can you please elaborate on why you think there is copying involved?
Or perhaps I'm doing something horribly wrong here...