Need help converting uint8_t array to NSMutableData

I am trying to pass some objective-c (mac) code to C ++ (win) code. However, I have a problem. On mac, my data comes in as an NSMutableData object, and in windows it enters the uint8_t array. I need to convert uint8_t data to the same data type that is inside NSMutableData. Help!

//on the mac
foo(NSMutableData* received)
{
   void* data = malloc([received length]);
   memcpy(data, [received mutableBytes], [received length]);

   bar(data);
}

//on windows
foo(const boost::shared_array<uint8_t>& received)
{
   void* data = ... //magic needs to happen here 

   bar(data);
}
+3
source share
2 answers

Is the tablet expected to receive a block of memory that it will own and free, as the Mac example shows?

void *data = malloc(received_size); //shared_array can't give you the size info
memcpy(data,received.get(),received_length);
bar(data);

If the bar does not gain ownership of the memory, you can simply transfer the data without copying:

void *data = static_cast<void*>(received.get());
0
source

; Windows , NSMutableData, , .

NSMutableData ; , uint8_t. , .

, NSMutableData uint8_t, , , , , MutableData.

,

0

All Articles