Quantcast

Pass 2D array from C++ to C#

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Pass 2D array from C++ to C#

howard.rubin
Is it possible to pass a 2D array from C++ to C#? The C# function would
receive it something like this:

public void Receive2dArray(int[,] m) {
}



--
View this message in context: http://mono.1490590.n4.nabble.com/Pass-2D-array-from-C-to-C-tp4670248.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
_______________________________________________
Mono-devel-list mailing list
[hidden email]
http://lists.dot.net/mailman/listinfo/mono-devel-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Pass 2D array from C++ to C#

Robert Jordan
On 14.03.2017 22:25, howard.rubin wrote:
> Is it possible to pass a 2D array from C++ to C#? The C# function would
> receive it something like this:
>
> public void Receive2dArray(int[,] m) {
> }


See mono_array_class_get () and mono_array_new_full ().



_______________________________________________
Mono-devel-list mailing list
[hidden email]
http://lists.dot.net/mailman/listinfo/mono-devel-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Pass 2D array from C++ to C#

howard.rubin
So I used mono_array_class_get () to create the class for the 2nd param to
mono_array_new_full (). Then I used mono_array_set() to set the values in
the created array, assuming contiguous array element storage.

    MonoClass* TwoDArrayClass = mono_array_class_get(mono_get_int32_class(),
2);
    uintptr_t lengths[] = { cells.size(), 2 };
    intptr_t lower_bounds[] = { 0, 0 };
    MonoArray* am = mono_array_new_full(domain, TwoDArrayClass, lengths,
lower_bounds);

    for (unsigned int i=0; i<cells.size(); ++i) {
        mono_array_set(am, int, 2*i, cells[i].first);
        mono_array_set(am, int, 1+2*i, cells[i].second);
    }




--
View this message in context: http://mono.1490590.n4.nabble.com/Pass-2D-array-from-C-to-C-tp4670248p4670257.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
_______________________________________________
Mono-devel-list mailing list
[hidden email]
http://lists.dot.net/mailman/listinfo/mono-devel-list
Loading...