Passing array sections to unmanaged code..

  • Thread starter Thread starter Atmapuri
  • Start date Start date
A

Atmapuri

Hi!

Is it possible to pass a subsection of an array
as a parameter to unmanaged code without
explicitely pinning down the array?

In unmanaged code you just pass a pointer to
to the first selected element, but here it seems you
have to either pin it down or make a separate copy...

Is there a better way?

Thanks!
Atmapuri
 
| Hi!
|
| Is it possible to pass a subsection of an array
| as a parameter to unmanaged code without
| explicitely pinning down the array?
|
| In unmanaged code you just pass a pointer to
| to the first selected element, but here it seems you
| have to either pin it down or make a separate copy...
|
| Is there a better way?

Using the unsafe keyword you can use pointers in C#, e.g.

public unsafe void Method()
{
int x = 10;
int y = 20;
int *ptr1 = &x;
int *ptr2 = &y;
}

Maybe this can help.

Chris.
 
Atmapuri said:
Is it possible to pass a subsection of an array
as a parameter to unmanaged code without
explicitely pinning down the array?

You might try the ArraySegment generic.

We've used it for similar things, but we always had the whole array pinned
(we allocate large arrays from the Large Object Heap, Pin Them, and then use
pieces of them as Windows Sockets buffers for BeginReceive/BeginSend type
calls).
 
Back
Top