G
Guest
Hi,
I am writing a mixed mode application, I have a mixed mode Assembly manipulating a managed byte[] array, to access this array in unmanaged code I '__pin' the array, As I understand, pining an object guarantee that it will not be collected by the GC ( by increasing it's refcount or so ), Taking that in mind, looking at the code generated by the compiler I can't see anything taking care of the GC refcount... following is the pinned variable with the corresponding dis-assembly section:
****************** Mixed mode C++ code line ******************
BYTE __pin *pbtArray = &btArray[0];
******************** The dis-assembly ***********************
00000019 cmp dword ptr [esi+4],0 // makes sure that NULL != &btArray[0]
0000001d ja 00000026 // if it is not NULL go three lines bellow
0000001f xor ecx,ecx
00000021 call 7227F90B // call some exception handling procedure...
00000026 lea eax,[esi+8] // get the address of &btArray[0] to eax
00000029 mov dword ptr [ebp-14h],eax // pbtArray = content of eax
********************************************************
Why there is no GC manipulation code? isn't it needed?
The original code:
********************************************************
virtual int NotArray(System::Byte btArray __gc[])
{
int i = 0;
BYTE __pin *pbtArray = &btArray[0];
for(i; i < btArray->Length; i++)
pbtArray <<= 1;
return 0;
}
Nadav
http://www.ddevel.com
I am writing a mixed mode application, I have a mixed mode Assembly manipulating a managed byte[] array, to access this array in unmanaged code I '__pin' the array, As I understand, pining an object guarantee that it will not be collected by the GC ( by increasing it's refcount or so ), Taking that in mind, looking at the code generated by the compiler I can't see anything taking care of the GC refcount... following is the pinned variable with the corresponding dis-assembly section:
****************** Mixed mode C++ code line ******************
BYTE __pin *pbtArray = &btArray[0];
******************** The dis-assembly ***********************
00000019 cmp dword ptr [esi+4],0 // makes sure that NULL != &btArray[0]
0000001d ja 00000026 // if it is not NULL go three lines bellow
0000001f xor ecx,ecx
00000021 call 7227F90B // call some exception handling procedure...
00000026 lea eax,[esi+8] // get the address of &btArray[0] to eax
00000029 mov dword ptr [ebp-14h],eax // pbtArray = content of eax
********************************************************
Why there is no GC manipulation code? isn't it needed?
The original code:
********************************************************
virtual int NotArray(System::Byte btArray __gc[])
{
int i = 0;
BYTE __pin *pbtArray = &btArray[0];
for(i; i < btArray->Length; i++)
pbtArray <<= 1;
return 0;
}
Nadav
http://www.ddevel.com