Click here to Skip to main content
15,565,894 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys!

i need to increment a pointer by one, just like this, i++.

dim i as system.intptr


how do i do that?

i+=1 doesn't works.


Help guys! ( well, gals can too! equally requested!)
Posted
Comments
TheMrProgrammer 27-Apr-11 7:00am    
thanks for the hints guys and pardon me for replying late!

actually i am not yet "allowed" to run the code, so i can't be sure my code will work or not, but I've
written two possible alternatives.

1.
<pre>Dim increment% = System.IntPtr.Size
i = i.ToInt32() + increment<pre/>


2.
<pre>Dim temp%
temp = Marshal.ReadInt32(i)
temp += System.IntPtr.Size
Marshal.WriteInt32(i, temp)<pre/>

which of them is correct?
can anyone of you tell me?

thanks!

There is no pointer arithmetic on this type!

This is very natural: this type assumes no size of the array elements, it can be anything rather then array where the pointer arithmetic makes no sense.

Actually, you should not modify the value of this type in any way. You can use arrays instead and System.Runtime.InteropServices.Marshal is you need to go to unmanaged types and back.

As to pointers in general, they are available in .NET only in unsafe mode. This is a managed platform!

—SA
 
Share this answer
 
v2
Comments
Nish Nishant 26-Apr-11 13:24pm    
Voted 5.
Sergey Alexandrovich Kryukov 26-Apr-11 13:31pm    
Thank you, Nishant.
--SA
CPallini 26-Apr-11 13:32pm    
My 5 too.
Sergey Alexandrovich Kryukov 26-Apr-11 13:49pm    
Thank you very much.
--SA
TheMrProgrammer 28-Apr-11 11:48am    
thanks for the hints guys and pardon me for replying late!

actually i am not yet "allowed" to run the code, so i can't be sure my code will work or not, but I've
written two possible alternatives.

1.
<pre>Dim increment% = System.IntPtr.Size
i = i.ToInt32() + increment<pre/>


2.
<pre>Dim temp%
temp = Marshal.ReadInt32(i)
temp += System.IntPtr.Size
Marshal.WriteInt32(i, temp)<pre/>

which of them is correct?
can anyone of you tell me?

thanks!
Have a look at this article:
Exploring general functions of the Marshal class[^]

Also, have a look at this tip:
Pointer Arithmetic Utility Struct[^]

Good luck!
 
Share this answer
 
Comments
Nish Nishant 26-Apr-11 13:24pm    
Voted 5 to counter the unfair 1 vote. Not sure if this will help the OP though.
CPallini 26-Apr-11 13:32pm    
Voted 5 because Nish did. Not sure if he was right though. :-D
Nish Nishant 26-Apr-11 13:58pm    
Geez man! :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900