By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,671 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,671 IT Pros & Developers. It's quick & easy.

IntPtr and fixed

P: n/a

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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.