将锯齿状数组byte [] []传递给非托管代码 [英] Passing jagged array byte[][] to unmanaged code

查看:70
本文介绍了将锯齿状数组byte [] []传递给非托管代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨大师,


我需要通过引用非托管

函数来传输一个参差不齐的byte [] []数组,非托管代码应该更改数组的值,当

非托管函数返回时,我需要向最终用户显示数组数据。


我可以这样做吗? br $> b $ b怎么样?

-------

谢谢

Sharon

解决方案

Sharon,


您将不得不手动编组,因为我不认为那里

是框架中的一种机制,可以自行处理。


你必须迭代遍历每个数组,动态

分配内存在非托管内存中,然后复制值。在

返回时,您必须将值复制回来。


不安全的代码在这里会有所帮助,因为您不必担心

关于分配和释放内存(你可以使用stackalloc来为你分配内存)。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse。 com


" Sharon" < sh ***** @ newsgroups.nospamwrote in message

news:9E ************************* ********* @ microsof t.com ...


嗨大师,


我需要通过引用转移一个参差不齐的

函数的字节[] []的锯齿状数组,非托管代码应该改变数组的值,并且



非托管函数返回我需要将数组数据显示到最后

用户。


我可以这样做吗?

如何?


-------

谢谢

Sharon



我担心这种工作会破坏性能,因为有很多

的数据需要复制。

我认为有一种方法可以通过引用在

非托管端使用托管阵列并避免内存复制。

如果没有解决方案,我想我会在本机C ++中编写更多的

代码(unmana这样做。


--------

谢谢

Sharon

"沙龙" < sh ***** @ newsgroups.nospamwrote in message

news:68 ************************* ********* @ microsof t.com ...


我担心这种工作会破坏性能,因为有一个

很多

要复制的数据。

我认为有一种方法可以通过引用来使用托管阵列

非托管端并避免内存复制。

如果没有解决方案,我想我会在本机C ++中编写更多的

代码(不受管理) )这样做。


--------

谢谢

Sharon



是什么让你觉得复制会成为一个问题?这些

阵列有多大?你为什么要使用锯齿状阵列,而这种类型

首先不能用C或C ++直接处理?


威利。


Hi Gurus,

I need to transfer a jagged array of byte[][] by reference to unmanaged
function, The unmanaged code should changed the values of the array, and when
the unmanaged function returns I need to show the array data to the end user.

Can I do that?
How?
-------
Thanks
Sharon

解决方案

Sharon,

You are going to have to marshal this manually, as I don''t think there
is a mechanism in the framework to handle this on your own.

You would have to iterate through each array of arrays, dynamically
allocating the memory in unmanaged memory, then copying the values. On
return, you would have to copy the values back.

Unsafe code would help a little bit here, as you wouldn''t have to worry
about allocating and deallocating the memory (you could use stackalloc to
allocate the memory for you).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sharon" <Sh*****@newsgroups.nospamwrote in message
news:9E**********************************@microsof t.com...

Hi Gurus,

I need to transfer a jagged array of byte[][] by reference to unmanaged
function, The unmanaged code should changed the values of the array, and
when
the unmanaged function returns I need to show the array data to the end
user.

Can I do that?
How?
-------
Thanks
Sharon



I''m afraid this kind of work will undermine the performance as there is a lot
of data to copy.
I thought there is a way to use the managed array by reference on the
unmanaged side and avoiding the memory copy.
If there is no solution for that, I think I will write some more piece of
code in native C++ (unmanaged) to do that.

--------
Thanks
Sharon


"Sharon" <Sh*****@newsgroups.nospamwrote in message
news:68**********************************@microsof t.com...

I''m afraid this kind of work will undermine the performance as there is a
lot
of data to copy.
I thought there is a way to use the managed array by reference on the
unmanaged side and avoiding the memory copy.
If there is no solution for that, I think I will write some more piece of
code in native C++ (unmanaged) to do that.

--------
Thanks
Sharon



What make you think that copying will be an issue? How large are these
array''s? And why are you using an jagged array, while this kind of type
can''t be handled directly in C or C++ in the first place?

Willy.


这篇关于将锯齿状数组byte [] []传递给非托管代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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