How to pass an array of integers or bytes (or a pointer) from objective-c to unity

I need to pass a large array of values from objective-c to unity C#

I suspect the first step is to cast the byte* array or int* array into a const char* array so it can be passed to UnitySendMessage.

It’s the unity side I’m wondering about. It gets a “string” object passed to it. Reading up on the string class it looks like it’s built by copying the characters out of the utf8 array passed to it’s ctor. I then want to decode it back into characters so I can then cast them as numbers. A bit worried about that.

Alternatively, can I just pass a pointer from the unmanaged code to the managed code? That seems optimal. Any advice appreciated.

I could be totally wrong here. But I just needed to pass my data to a IOS CoreMIDI call and I felt reasonably comfortable that the pointers would stay around and owned by Unity long enough for the function call to return. So I just did the following:

byte[] ba = new byte[3];
ba[0] = 144; //note on
ba[1] = 65; //note number
ba[2] = 90; //velocity
MIDIImports.midi_send(ba, 3);

------- midi send is defined as

public static extern void midi_send(byte[] b, int siz);

Then on the Obj C side

extern "C"
{
  void midi_send(UInt8* b, Int32 siz);
}

On the surface it seemed to work… haven’t really stress tested it yet though.