*int Vs IntPtr

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

Guest

yello...

Assuming a 32bit system for this Q..
Is there any proformance differences between an *int vs IntPtr ??

I know that the IntPtr can be an Int32* or an Int64* (or more) depending
on the hardware.

thanks in advance.
 
Is there any proformance differences between an *int vs IntPtr ??

I strongly doubt it. They are treated pretty much the same at runtime.


Mattias
 
Hi,

I doubt that an acceptable level of performance for your application hinges on
the decision to use pointers instead of IntPtr, so you probably shouldn't
worry to much about this :)
 
TheMadHatter said:
yello...

Assuming a 32bit system for this Q..
Is there any proformance differences between an *int vs IntPtr ??

I know that the IntPtr can be an Int32* or an Int64* (or more) depending
on the hardware.

Surely IntPtr would be slower as you need to copy data back and forward to
arrays in order to use it. If you're just passing a pointer around then I
couldn't see any difference and you're probably better using the managed
version.

Michael
 
Michael said:
Surely IntPtr would be slower as you need to copy data back and forward to
arrays in order to use it. If you're just passing a pointer around then I
couldn't see any difference and you're probably better using the managed
version.

Michael

Hi Michael,
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?
 
Tom Spink said:
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++;
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++;

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

Michael
 
Michael C said:
Tom Spink said:
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++;
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++;

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

Michael

I'll remember that marshal.Copy(,,)

Ofcourse you could just cast the ptr.

//eg:
IntPtr ptr1 = somethingFromSomeWhere();
byte* bytePtr1 = (byte*)ptr1; //No array copying involved. :)
for(int x = 0;x < 32; x++)
bytePtr1[x]++;
 
Perhaps I should look into directx...but...
When it comes to drawing on a graph,
the only way to make gdi work any faster is to write
around it. (went from 90% processor to 45%, then
blew it off on faster frame rate.)
 
TheMadHatter said:
Perhaps I should look into directx...but...
When it comes to drawing on a graph,
the only way to make gdi work any faster is to write
around it. (went from 90% processor to 45%, then
blew it off on faster frame rate.)

Are you writing graphics routines that iterate over each pixel, or
something like that? This is unusual for games. Normally the per-pixel
algorithms (and indeed the per-vertex algorithms) are executed on the
graphics card. You leave the CPU for higher-level stuff.
 
Hi,

....so it seems DirectX might be a better choice than GDI or GDI+.
 
Hi,
Yup, but that is a learning curve for another day. :)

The tutorials for MDX are quite easy to use. You really only need knowledge
of C# and a basic understanding of math such as matrices and vectors to get
something going. Of course, if you really don't have the time then that's a
different story :)

"Microsoft DirectX and XNA, How Do I...?"
http://msdn.microsoft.com/archive/d..._Aug_2005/directx/howdoi_entry.asp?frame=true
I was looking into the directdraw, but they are trying to do
their best to get rid of it. :(

I really don't think DirectDraw is any easier to code against than Direct3D
anyway. If you're interested in giving it a shot (I highly recommend it - I
wish I had time to get better at it myself), I think you'll be surprised at
how easy it is. (and admittedly frustrating at times also, depending on the
complexity of your goals :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top