IntPtr and fixed

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All

Is IntPtr a managed or unmanaged data type in c#

Do I need to be doing
Intptr = IPtr
fixed(void * ptr = (void *)IPtr


....


to avoid relocation? or can I use

void *ptr = (void *)Iptr without fixed

thank yo
vipin
 
Is IntPtr a managed or unmanaged data type in c#?

Managed. C# only produces managed code, you can't have any unmanaged
types.

Do I need to be doing
Intptr = IPtr;
fixed(void * ptr = (void *)IPtr )
{


....
}

to avoid relocation? or can I use


void *ptr = (void *)Iptr without fixed?


Most likely no, but it depends on what the IntPtr is pointing at. I
assume you wouldn't have an IntPtr pointing to something managed
unless you had already pinned it. The first piece of code won't work
though.



Mattias
 
IntPtr points to a View returned by calling DLLImport MapViewOfFIle from kernel32.dll.

Then there's no need to pin anything. The handle refers to an
unmanaged resource that's not affected by the GC anyway.



Mattias
 
Back
Top