Objective c 马赫数vm映射(大小=)失败(错误代码=3)

Objective c 马赫数vm映射(大小=)失败(错误代码=3),objective-c,alassetslibrary,Objective C,Alassetslibrary,我正在尝试将视频从相册保存到文档目录。对于不到1分钟的视频,它可以正常工作。但当我试图保存超过1分钟的视频时,我的应用程序崩溃了。这只发生在iPhone上,在iPad上,它也适用于更大的视频 这是我的代码: else if([mediaType isEqualToString:ALAssetTypeVideo]) { ALAssetsLibrary *librarys = [[ALAssetsLibrary alloc] init]; [libr

我正在尝试将视频从相册保存到文档目录。对于不到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];
错误:

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

我在使用核心音频时遇到了这个错误。我可以通过将编译器优化设置为“-O0 None”来修复此问题。

在您的帖子中,我会说您请求的内存太多…@Volker是否有任何训练可以在不消耗太多内存的情况下保存这些视频?拆分内存使用。。。或者使用交换文件。。。一个环形缓冲区。。。任何能减少内存分配大小的东西。hi@volker…riven的回答解决了我的问题。
 malloc: *** mach_vm_map(size=310386688) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug