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

前端之家收集整理的这篇文章主要介绍了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&C++相关文章