473,395 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 5243
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Logan McKinley | last post by:
I have a third party Dll with a function which requires an IntPtr but the data is in a byte array. I need to get the IntPtr for this byte array so I can pass it into the function. Thanks in...
0
by: vipin | last post by:
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 ....
1
by: vipin aravind | last post by:
Hi, In C#, I do DllImport of MapViewOfFile(...) which will return IntPtr. The (void *) operator gives me the pointer way of working on the memory. My question is do I need to use ...
13
by: Christian Westerlund | last post by:
Hi! I'm trying to use P/Invoke and a Method which takes an IntPtr where I am supposed to put an address to a method which the native method will use to communicate back to me. How do I convert a...
10
by: Tamir Khason | last post by:
I have a pointer to array and I want to apply indexing to this Array so I have function (name it IntPrt Func) to go to certain member I can use (as C++) Func, but in C# I recieve an error "Cannot...
1
by: zishen yan | last post by:
Hello, I have a question confused me a long time. I am working on DirectDraw .NET a while. And I want to copy data to surface, but I found Surface.Lock return System.Array. I tried to cast it to...
7
by: justin.kruger | last post by:
I am having a problem with exchanging handles with c# and the "CP210xManufacturing.dll" in a device wrapper that i am working on. I have created a wrapper class to address some of the functions...
0
by: cewood | last post by:
Hi, I was hoping someone could help me with the following: I'm writing code to try and get a image from a USB camera mfg. dll. Here's the dll function: SDK_API MTUSB_GetCurrentFrame(...
2
by: O.B. | last post by:
I have a class that has an Explicit StructLayout. In the constructor below, I am copying data from a byte array onto this class so as to initialize all the explicit attributes of the class. What...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.