如何在vb.net 2003中移动intptr [英] How to move a intptr in vb.net 2003

查看:83
本文介绍了如何在vb.net 2003中移动intptr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个简单的例子,从内存指针位置开始,我需要做10个
操作,(例如将10个值复制到数组中),然后当

时完成之后,将指针移动到第11个位置,这样我就可以使用接下来的十个值来等待


Dim Ptr1 as IntPtr

对于x = 0到100

''执行类似于从此块中获取10个值的内容,

始终在ptr1

''接下来将指针移动到一个新位置10个单位,这样我就可以接下来
接下来的10个值

ptr1 = Ptr1 + 10''不起作用

next x


如何在vb.net 2003中执行此操作


感谢您的帮助

Bob

解决方案

Robert Dufour写道:


As一个简单的例子,从内存指针位置开始,我需要做10个b $ b操作,(比如复制10个例如,对于一个数组的值),然后当

完成时,将指针移动到第十一个位置,这样我就可以使用接下来的10个值来支持
,等等

Dim Ptr1 as IntPtr

对于x = 0到100

''从这个块中获取10个来自内存的值,

最初在ptr1

''接下来将指针移动到新位置10个单位,这样我就可以接下来$ / b $ b接下来的10个值
ptr1 = Ptr1 + 10''不起作用

next x



我不知道支持使用IntPtr的指针算术。也许

你可以通过手动递增指针来获得,但这需要经过深思熟虑才能获得
。你需要指向10 *字节*

的位置还是10个*元素*的位置?如果是前者,你需要考虑元素的大小。打电话给

System.Runtime.InteropServices.Marshal在这种情况下会有所帮助。


< aircode>

'' 10 *字节*远

Ptr =新IntPtr(Ptr.ToInt64 + 10)


Ptr = New IntPtr(Ptr.ToInt64 + 10 * _

System.Runtime.InteropServices.Marshal.SizeOf(Elem entType))

< / aircode>

HTH。


问候,


布兰科。


罗伯特,


" ptr1 = Ptr1 + 10''不起作用


我不是在vb.net上有很多指针经验(现在几个月只用了几个月来编程vb.net)

在C ++中(在这里和我一起)增加一个指针将沿着它指向/引用的数据类型的大小字节移动

,这个

我不认为是vb.net的情况


我认为增加一个.net中的IntPtr只会让它在内存中向前移动一个字节,所以除非你的数组的类型是byte。或者char

它不会以正确的偏移量移动。


所以假设你指向一个整数数组(在32位电脑)

然后


ptr1 = Ptr1 + 40


ptr1 = ptr1 + 10 * dataTypeSize


问候,


Mike

" Robert Dufour的" < bd ***** @ sgiims.com写信息

新闻:eb ************** @ TK2MSFTNGP02.phx.gbl ...


作为一个简单的例子,从内存指针位置开始,我需要做
10次操作,(比如将10个值复制到数组) ,然后

完成后,将指针移动到第十一位置,这样我就可以使用接下来的十个值等等


Dim Ptr1 as IntPtr

x = 0到100

''从这个块中获取10个值来自内存,

初始在ptr1

''接下来将指针移动到新位置10个单位,这样我就可以接下来
接下来的10个值

ptr1 = Ptr1 + 10''不起作用

next x


你怎么能在vb.net 2003中这样做


感谢您的帮助

Bob



对不起,我有点重复你回答的内容ered,你的帖子不可见

当我点击回复组按钮时。


" Branco Medeiros" < br ************* @ gmail.com写信息

新闻:11 ***************** *****@y80g2000hsf.googlegr oups.com ...


Robert Dufour写道:


>作为一个简单的例子,从一个内存指针位置开始,我需要做一些操作,(比如将10个值复制到一个数组),然后当这个'是完成后,将指针移动到第十一个位置,这样我就可以使用接下来的十个值等等。
Dim Ptr1 as IntPtr
对于x = 0到100
''做比如从这个区块的内存中获取10个值,
最初在ptr1
''接下来将指针移动到新位置10个单位,这样我就可以接下来10个接下来的10个价值
ptr1 = Ptr1 + 10''不起作用
下一个x



我不知道用IntPtr支持指针运算'的。也许

你可以通过手动递增指针来获得,但这需要经过深思熟虑才能获得
。你需要指向10 *字节*

的位置还是10个*元素*的位置?如果是前者,你需要考虑元素的大小。打电话给

System.Runtime.InteropServices.Marshal在这种情况下会有所帮助。


< aircode>

'' 10 *字节*远

Ptr =新IntPtr(Ptr.ToInt64 + 10)


Ptr = New IntPtr(Ptr.ToInt64 + 10 * _

System.Runtime.InteropServices.Marshal.SizeOf(Elem entType))

< / aircode>


HTH。


问候,


布兰科。



As a simple example starting with a memory pointer location I need to do 10
operations, (like copying 10 values to an array for instance), then when
that''s done, move the pointer to the eleventh location so that I can then
use the next ten values, etc
Dim Ptr1 as IntPtr
For x = 0 to 100
''Do something like getting 10 values from memory from this block,
initailly at ptr1
''next move the pointer to a new position 10 units so that I can pickup
the next 10 values
ptr1 = Ptr1 + 10 ''Does not work
next x

How can you do this in vb.net 2003

Thanks for any help
Bob

解决方案

Robert Dufour wrote:

As a simple example starting with a memory pointer location I need to do 10
operations, (like copying 10 values to an array for instance), then when
that''s done, move the pointer to the eleventh location so that I can then
use the next ten values, etc
Dim Ptr1 as IntPtr
For x = 0 to 100
''Do something like getting 10 values from memory from this block,
initailly at ptr1
''next move the pointer to a new position 10 units so that I can pickup
the next 10 values
ptr1 = Ptr1 + 10 ''Does not work
next x

I''m not aware of support for pointer arithmetic with IntPtr''s. Maybe
you can get by with manual incrementing of the pointer, but this needs
to be well thought out. Do you need to point to a position ten *bytes*
away or one ten *elements* away? If the former, you''ll need to
consider the element''s size. A call to
System.Runtime.InteropServices.Marshal would help in this case.

<aircode>
''ten *bytes* away
Ptr = New IntPtr(Ptr.ToInt64 + 10)

''ten *elements* away
Ptr = New IntPtr(Ptr.ToInt64 + 10 * _
System.Runtime.InteropServices.Marshal.SizeOf(Elem entType))
</aircode>
HTH.

Regards,

Branco.


Hi Robert,

"ptr1 = Ptr1 + 10 ''Does not work"

I don''t have a whole bunch of experience with pointers in vb.net (only been
programming vb.net a few months now)
In C++ (bare with me here) Incrementing a pointer is going to move it along
as many bytes as the sizeof the datatype it is pointing / refering to, this
I do not think is the case with vb.net

I think that incrementing an IntPtr in .net is only going to make it walk
one byte forward in memory, so unless your array is of type "byte" or "char"
it is not going to be moving with the correct offset.

so lets say you are pointing to an array of integers (on 32 bit computer)
then

ptr1 = Ptr1 + 40

Or in other words:
ptr1 = ptr1 + 10 * dataTypeSize

Regards,

Mike
"Robert Dufour" <bd*****@sgiims.comwrote in message
news:eb**************@TK2MSFTNGP02.phx.gbl...

As a simple example starting with a memory pointer location I need to do
10 operations, (like copying 10 values to an array for instance), then
when that''s done, move the pointer to the eleventh location so that I can
then use the next ten values, etc
Dim Ptr1 as IntPtr
For x = 0 to 100
''Do something like getting 10 values from memory from this block,
initailly at ptr1
''next move the pointer to a new position 10 units so that I can pickup
the next 10 values
ptr1 = Ptr1 + 10 ''Does not work
next x

How can you do this in vb.net 2003

Thanks for any help
Bob



Sorry I have kind of repeated what you answered, your post was not visible
when I hit the reply group button.

"Branco Medeiros" <br*************@gmail.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...

Robert Dufour wrote:

>As a simple example starting with a memory pointer location I need to do
10
operations, (like copying 10 values to an array for instance), then when
that''s done, move the pointer to the eleventh location so that I can then
use the next ten values, etc
Dim Ptr1 as IntPtr
For x = 0 to 100
''Do something like getting 10 values from memory from this block,
initailly at ptr1
''next move the pointer to a new position 10 units so that I can
pickup
the next 10 values
ptr1 = Ptr1 + 10 ''Does not work
next x


I''m not aware of support for pointer arithmetic with IntPtr''s. Maybe
you can get by with manual incrementing of the pointer, but this needs
to be well thought out. Do you need to point to a position ten *bytes*
away or one ten *elements* away? If the former, you''ll need to
consider the element''s size. A call to
System.Runtime.InteropServices.Marshal would help in this case.

<aircode>
''ten *bytes* away
Ptr = New IntPtr(Ptr.ToInt64 + 10)

''ten *elements* away
Ptr = New IntPtr(Ptr.ToInt64 + 10 * _
System.Runtime.InteropServices.Marshal.SizeOf(Elem entType))
</aircode>
HTH.

Regards,

Branco.



这篇关于如何在vb.net 2003中移动intptr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆