473,509 Members | 3,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'__pin' Seem to do nothing...

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[i] <<= 1;
return 0;
}

Nadav
http://www.ddevel.com
Nov 17 '05 #1
3 1073
Look at the IL/meta data generated. It will have a pinned modifier on the
storage location. That is sufficient for the GC to know how to handle this.

Ronald Laeremans
Visual C++ team

"Nadav" <Na***@discussions.microsoft.com> wrote in message
news:A2**********************************@microsof t.com...
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[i] <<= 1;
return 0;
}

Nadav
http://www.ddevel.com

Nov 17 '05 #2
Hi Ronald, Thanks for your immediate responce, Taking in mind what you have said, Still there should be some code that 'tells' the GC to 'read' this meta-data, where is this code? how does the GC know to use the pinned variable meta-data? any pointers, samples or any useful information would be appriciated...

Nadav
http://www.ddevel.com

"Ronald Laeremans [MSFT]" wrote:
Look at the IL/meta data generated. It will have a pinned modifier on the
storage location. That is sufficient for the GC to know how to handle this.

Ronald Laeremans
Visual C++ team

"Nadav" <Na***@discussions.microsoft.com> wrote in message
news:A2**********************************@microsof t.com...
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[i] <<= 1;
return 0;
}

Nadav
http://www.ddevel.com


Nov 17 '05 #3
It is in the runtime code for the garbage collector itself. It doesn't need
to be in the generated assembly for your program. The code to do the garbage
collection itself likewise isn't emitted as part of your program. The GC
code uses the meta data directly.

Ronald

"Nadav" <Na***@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
Hi Ronald, Thanks for your immediate responce, Taking in mind what you
have said, Still there should be some code that 'tells' the GC to 'read'
this meta-data, where is this code? how does the GC know to use the pinned
variable meta-data? any pointers, samples or any useful information would
be appriciated...

Nadav
http://www.ddevel.com

"Ronald Laeremans [MSFT]" wrote:
Look at the IL/meta data generated. It will have a pinned modifier on the
storage location. That is sufficient for the GC to know how to handle
this.

Ronald Laeremans
Visual C++ team

"Nadav" <Na***@discussions.microsoft.com> wrote in message
news:A2**********************************@microsof t.com...
> 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[i] <<= 1;
> return 0;
> }
>
> Nadav
> http://www.ddevel.com


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3350
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to...
1
2087
by: Sai Kit Tong | last post by:
I have to interface managed application with my legacy dll. I have employed the wrapper approach but I have to deal with the asynchronous callback from the legacy dll, which likely goes through a...
3
1787
by: Nadav | last post by:
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...
3
2205
by: Hexar Anderson | last post by:
I have two questions: a) From documentation located at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmxspec/html/vcManagedExtensionsSpec_7_7.asp, it says, "Pinning a...
4
4506
by: Avlan | last post by:
Hi, I'm pretty new with ASP-coding, but I got a simple login working. I let the user enter a username and password and through a SQL-statement I check if there is a corresponding password in the...
1
955
by: rob | last post by:
I have the following code: int Function(short buffer __gc) { .... short __pin* inPinned = & buffer; DoSomethingUnsafe(inPinned) ... } &buffer shows a valid address but when I pin it down...
3
1280
by: Luke - eat.lemons | last post by:
Sorry for the post in this NG but im short on time to get this working and i haven't seem to of got a response anywhere else. Im pretty new to asp so all light on this question would be great. ...
2
2276
by: majestic12 | last post by:
This is the first time I've tried to use mysql/phpmyadmin and I'm having trouble. I'm using a geocites pro account and I got both installed and it set up a database call mysql and the user yroot. ...
4
1404
by: recurr | last post by:
How to get what a variable is dimmed as? How to get what an object is declared as? If variable or object is Nothing? I want to do something like the following, but TypeOf and GetType doesn't...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.