472,122 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,122 software developers and data experts.

IntPtr and fixed


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
Nov 15 '05 #1
3 4909
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #2
IntPtr points to a View returned by calling DLLImport MapViewOfFIle from kernel32.dll

I am compiling the code with /unsafe switch

vipin
Nov 15 '05 #3
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Logan McKinley | last post: by
reply views Thread by vipin | last post: by
1 post views Thread by vipin aravind | last post: by
13 posts views Thread by Christian Westerlund | last post: by
10 posts views Thread by Tamir Khason | last post: by
1 post views Thread by zishen yan | last post: by
2 posts views Thread by O.B. | last post: by
reply views Thread by leo001 | last post: by

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.