Re: *int Vs IntPtr



"Tom Spink" <tspink@xxxxxxxxx> wrote in message
news:%23FVOGbNCHHA.3228@xxxxxxxxxxxxxxxxxxxxxxx
Surely IntPtr would be slower as you need to copy data back and forward
to
arrays in order to use it.

Can you explain what you mean by this?

Sure, if you have an intptr to some memory and you want to, say, increment
every byte by 1 you would need to do this:

IntPtr ptr = GetPointerFromSomewhere();
byte[] data = new byte[32];
marshal.Copy(ptr, data, 32); //can't remember exact syntax
for(int i = 0; i < 32; i++) data[i]++;
marshal.Copy(data, ptr, 32);

But if you have a byte* you don't need the 2 copies:
byte* ptr = GetPointerFromSomewhere();
for(int i = 0; i < 32; i++) ptr[i]++;

Of course this is irrelevant if you are just keeping a pointer to pass to
API calls etc.

Michael


.



Relevant Pages

  • Re: External listview control memory exception when sendmessage is
    ... Someone suggested to increase the LVITEM memory size but that didn't work. ... Do you have any idea if that ListView is owner drawn, ... IntPtr mainWindowHwnd; ... LVITEM lvi = new LVITEM; ...
    (microsoft.public.win32.programmer.ui)
  • Re: External listview control memory exception when sendmessage is
    ... Someone suggested to increase the LVITEM memory size but that didn't work. ... Do you have any idea if that ListView is owner drawn, ... IntPtr mainWindowHwnd; ... LVITEM lvi = new LVITEM; ...
    (microsoft.public.win32.programmer.ui)
  • Re: memory device context and DIB
    ... IntPtr dib = CreateDIBSection(hMemDC, ref bmi, DIB_RGB_COLORS, ... IntPtr bits = IntPtr.Zero; ... I have not found any mention of or code examples using DIBSections and OpenGL online. ... Another thing I would like to read up on is what exactly is involved in the process of marshalling managed memory to unmanaged memory, ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: External listview control memory exception when sendmessage is
    ... comes to Listview there I got memory exception. ... I know that I need to do the in memory processing with the external ... IntPtr mainWindowHwnd; ... LVITEM lvi = new LVITEM; ...
    (microsoft.public.win32.programmer.ui)
  • Re: Problem with Marshal class in Visual Studio 2005
    ... IntPtr ptr = new IntPtr0xa8702004); ... | private static extern void MyWriteInt32(IntPtr addr, Int32 offset, ...
    (microsoft.public.dotnet.languages.csharp)

Loading