Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从Objective-C+存储/检索值+;目标C_Iphone_Objective C_Ios_Xcode_Objective C++ - Fatal编程技术网

Iphone 从Objective-C+存储/检索值+;目标C

Iphone 从Objective-C+存储/检索值+;目标C,iphone,objective-c,ios,xcode,objective-c++,Iphone,Objective C,Ios,Xcode,Objective C++,如何将下面这样的Objective-C++短int存储在Objective-C数组中,并在以后将其转换回Objective-C++?我尝试了以下方法,但没有成功。任何帮助都会很好 short int *tmpbuffer = ( short int*)malloc(sizeof(short int)*length*inData); int count = 0; for (count = 0; count < length*inData; count++) { tmpbuffer[

如何将下面这样的Objective-C++短int存储在Objective-C数组中,并在以后将其转换回Objective-C++?我尝试了以下方法,但没有成功。任何帮助都会很好

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];
short int*tmpbuffer=(short int*)malloc(sizeof(short int)*length*inData);
整数计数=0;
对于(计数=0;计数 >P>不需要对简单的字节缓冲区进行目标C++和Objc的转换。您可以在目标C++与目标C类之间传递<代码>短INT/COM>指针。
如果您的意思是,如何将
short int
字节缓冲区转换为
NSArray
,那么您的思路是正确的,只需执行以下操作:

short int *buffer = malloc(size * sizeof(short int));
NSMutableArray *shortArray = [NSMutableArray arrayWithCapacity:size];
for (NSUInteger i = 0; i < size; i++) {
    [shortArray addObject:[NSNumber numberWithShort:buffer[i]]];
}
short int*buffer=malloc(size*sizeof(short int));
NSMutableArray*shortArray=[NSMutableArray阵列容量:大小];
对于(整数i=0;i
不过我不推荐这种方法,因为它效率不高,最好还是坚持使用C风格的缓冲区