byte []到byte * ...最快的方法是什么? [英] byte[] to byte*... What is the fastest way?

查看:83
本文介绍了byte []到byte * ...最快的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



主题说明了一切...我想使用byte []并将其用作byte *所以我

可以将指针递增到迭代它。


C#中最快的方法是什么?


谢谢


ThunderMusic

Hi,
The subject says it all... I want to use a byte[] and use it as byte* so I
can increment the pointer to iterate through it.

What is the fastest way of doing so in C#?

Thanks

ThunderMusic

推荐答案

ThunderMusic,


使用不安全的代码:


byte [] bytes = ...;


不安全

{

固定(字节* p =字节) )

{

//在这里使用指针。

}

}

事实上,这是唯一的方法,因为你需要在阵列的位置固定
以防止引用移动。


您是否有理由需要指针,或者您只是想寻找一种更快的方式来迭代数组?

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com

" ThunderMusic" < No ************************* @ NoSpAm.com写信息

新闻:%2 **** ************ @ TK2MSFTNGP04.phx.gbl ...
ThunderMusic,

Use unsafe code:

byte[] bytes = ...;

unsafe
{
fixed (byte* p = bytes)
{
// Work with pointer here.
}
}

As a matter of fact, that''s the only way to do it, as you need to pin
down the location of the array to prevent the reference from moving around.

Is there a reason you need the pointer, or are you just looking for a
faster way to iterate through the array?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ThunderMusic" <No*************************@NoSpAm.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...



主题说这一切...我想使用byte []并将其用作byte *所以我

可以递增指针以迭代它。


在C#中这样做的最快方法是什么?


谢谢


ThunderMusic
Hi,
The subject says it all... I want to use a byte[] and use it as byte* so I
can increment the pointer to iterate through it.

What is the fastest way of doing so in C#?

Thanks

ThunderMusic



>主题说明了一切...我想使用byte []并将其用作byte *所以我
>The subject says it all... I want to use a byte[] and use it as byte* so I

>可以递增指针以迭代它。

在C#中这样做的最快方法是什么?
>can increment the pointer to iterate through it.

What is the fastest way of doing so in C#?



固定报表?

Mattias


-

Mattias Sj?gren [C#MVP] mattias @ mvps.org
http:/ /www.msjogren.net/dotnet/ | http://www.dotnetinterop.com

请回复到新闻组。

The fixed statement?
Mattias

--
Mattias Sj?gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.





" ThunderMusic" < No ************************* @ NoSpAm.com写信息

新闻:%2 **** ************ @ TK2MSFTNGP04.phx.gbl ...
Hi,

"ThunderMusic" <No*************************@NoSpAm.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...



主题说这一切...我想使用byte []并将其用作byte *所以我

可以递增指针以迭代它。


在C#中这样做的最快方法是什么?
Hi,
The subject says it all... I want to use a byte[] and use it as byte* so I
can increment the pointer to iterate through it.

What is the fastest way of doing so in C#?



出于好奇,为什么要这样做?


使用像

for(int i = 0; i< buffer.Lengh; i ++

buffer [i] .....

Out of curiosity, why you want to do that?

What is wrong with using a indexer like
for( int i=0; i< buffer.Lengh; i++
buffer[i] .....


这篇关于byte []到byte * ...最快的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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