How can I store an Objective-C++ short int like the one below in an Objective-C array and convert it back to Objective-C++ later? I’ve attempted the following with no success. Any help would be great!
short int *tmpbuffer = ( short int*)malloc(sizeof(short int)*length*inData);
int count = 0;
for (count = 0; count < length*inData; count++)
{
tmpbuffer[count] = (short int) (inbuffer[count] * 0x7fff);
}
size = fwrite(tmpbuffer, 1, sizeof(short int)*length*inData,fp);
[fwriteSections addObject:[NSNumber numberWithShort:tmpbuffer]];
[fwriteSections addObject:[NSNumber numberWithShort:sizeof(short int)*length*inchannels]];
[fwriteRows addObject:fwriteSections];
There is no need to do any conversion between Objective C++ and Objective C for a simple byte buffer. You can just pass a
short intpointer between Objective C++ and Objective C classes.If you mean, how can you convert a
short intbyte buffer to anNSArray, then you are on the right track, just do the following:I would not recommend this approach though, it is not efficient, you are better off just sticking with the C style buffer.