Passing a matlab array into C# DLL

조회 수: 2 (최근 30일)
John
John 2013년 2월 7일
I have C# interfaces to a proprietary (internal) image processing library.
Interfaces look something like this:
void RGBConvert::ConvertFromRGBToYCbCr(
int ncols,
int nrows,
IntPtr rgb,
IntPtr out)
Where IntPtr is a pointer to the underlying memory. I have called .NET objects many times from Matlab, but passing large data arrays into C# is not something I've done, and am reaching a dead end.
The Matlab manual: http://www.mathworks.com/help/matlab/matlab_external/handling-net-data-in-matlab_bte9oxc-1.html#bte9o7y-1 indicates that IntPtr is not supported. By which I mean, it doesn't covert an array of Unsigned8Bit integers into an IntPtr to pass to the method. (If you construct an IntPtr through some other mechanisms, Matlab will treat it like any other .NET object and pass it around.) So, how do I find a pointer to the Matlab data, and pass it to this method?
Clearly, one approach would be to use the normal Matlab C/C++ interfaces to "trick" matlab into revealing the pointer to the underlying array data structure, and then pass that pointer to the IntPtr constructor. Then pass the IntPtr on. We had hoped to have a "pure" C# implementation, and to not have to have a C/C++ interface in addition to the C# interface.
Another avenue might be to take the Matlab ConvertArray call, to convert a matlab array to a .NET array, but then I still need an IntPtr pointing at the raw data.
I don't mind extraneous memory copies here, this is not performance critical code, this is experimentation code.
Anyone have experience with this issue, and recommendations?
Thoughts?

답변 (1개)

Conrad
Conrad 2013년 2월 8일
Hi John, what about creating a wrapper method with signature
double[,] RGBConvertWRP(int ncols,
int nrows,
double[,] rgb)
and then using NET.convertArray to pass the rgb variable to this new method? You can then just call your original RGBConvert method from this newly created wrapper method?
Conrad
  댓글 수: 1
John
John 2013년 2월 12일
@Conrad the NET.convertArray calls create .NET arrays, and not c++ arrays, which is what an IntPtr points to.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Compiler SDK에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by