objective-c – mach_vm_map(size =)失败(错误代码= 3)

我正在尝试将视频从相册保存到我的文档目录.它适用于不到1分钟的视频.但是当我试图保存视频超过1分钟时,我的应用程序正在崩溃.这种情况只发生在iPhone上,在iPad中它正在为更大的视频工作.

这是我的代码

else if([mediaType isEqualToString:ALAssetTypeVideo])
    {
        ALAssetsLibrary *librarys = [[ALAssetsLibrary alloc] init];

        [librarys enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group,BOOL *stop)
         {
             [group setAssetsFilter:[ALAssetsFilter allVideos]];

             if ([group numberOfAssets] > 0)
             {
                 for (int j = 0; j < [group numberOfAssets]; j++)
                 {
                     [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:j]
                                             options:0
                                          usingBlock:^(ALAsset *alAsset,NSUInteger index,BOOL *innerStop)
                      {
                          if (alAsset)
                          {
                              ALAssetRepresentation *representation = [alAsset defaultRepresentation];
                              NSURL *url = [representation url];

                              if ([[dict objectForKey:@"UIImagePickerControllerReferenceURL"] isEqual:url])
                              {
                                  Byte *buffer = (Byte*)malloc((unsigned)[representation size]);
                                  //NSUInteger buffered = [representation getBytes:buffer fromOffset:0.0 length:representation.size error:nil];
                                  //Byte *buffer = ((Byte*)representation.size);
                                  //NSUInteger chunkSize = 100 * 1024;
                                 // uint8_t *buffer = malloc(chunkSize * sizeof(uint64_t));

                                  NSUInteger buffered = [representation getBytes:buffer fromOffset:0.0 length:(NSUInteger)representation.size error:nil];
                                  NSData *videoCameraData = [NSData dataWithBytesNocopy:buffer length:buffered freeWhenDone:YES];
                                  Nsstring *savedImagePath = [docDirectory stringByAppendingPathComponent:str_Header];
                                  NSError *error;
                                  [[NSFileManager defaultManager] createDirectoryAtPath:savedImagePath withIntermediateDirectories:NO attributes:nil error:&error];

我的应用程序正在崩溃:

NSUInteger buffered = [representation getBytes:buffer fromOffset:0.0 length:(NSUInteger)representation.size error:nil];

错误

malloc: *** mach_vm_map(size=310386688) Failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

解决方法

我在使用Core Audio时遇到了这个错误.我能够通过将编译器优化设置为“-O0无”来修复它.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...