HUGE NSString decoding, out of memory

I’m looking for ideas on how to improve the decoding process of a 40 MB base64 encoded NSString and save it to a file, with the ability to fine-tune the process on the iPad's 1 256 MB RAM.

I get NSString from NSXMLParser:

id pointerToString;

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if ([currentElement isEqualToString:@"myElement"]) 
    {
    pointerToString = [string retain];
}
}

Then I use the ToString pointer in the callback:

[handler performSelector: action withObject: pointerToString];

In the callback (id value is a ToString pointer). I initialize the NSData with a ToString pointer, decoding it with base64 encoding.

^(id value)
{
    if ( [[value class] isSubclassOfClass:[NSString class]] ) 
    {
    NSData *data = [NSData dataFromBase64String:value];
    [data writeToFile:file.path atomically:YES];
}
}

iPad 1 runs out of memory and is killed by iOS when the memory allocation reaches about 130 MB after or during an NSData call.

I decided that to handle 40 MB of NSString in this way I would need about 180 MB of RAM (this is that the maximum memory allocation on the iPad 2 and 3, where the process works because of more RAM)

Any ideas / tips?

thank

+2
2

Edit

, , , , . , foundCharacters , .

XML :

  • XML

  • XML ;

  • Base64- .

, , XML . , 50 , , XML , Base64, Base64- , .

( , XML- , Base64-), . Apple XMLPerformance. , XML-, NSXMLParser, , LibXML. NSXMLParser , XML , , initWithContentsOfURL.

, , initWithContentsOfURL, NSXMLParser URL . foundCharacters NSXMLParserDelegate NSURLConnectionDelegate, didReceiveData, , NSXMLParser , NSURLConnection, , . , .

LibXML, , Apple XMLPerformance, NSURLConnection , , XML .

, Apple XMLPerformance. XML 56 100 NSXMLParser, 2 LibXML2.


Base64 . , , , . , ( ). , , Base64, , . , NSURLConnection, NSOutputStream, didReceiveData, .

. didReceiveResponse AdvancedGetController.m Apple AdvancedURLConnections , , NSMutableData ( , ). ( AdvancedURLConnections .., , NSOutputStream .) , , . LibXML2, Apple XMLPerformance, .

+2

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string

, .  

" , , ."

. , (, ). , , :

-writeData: 

-seekToEndOfFile 

NSFileHandle NSData .

base64 !

0

Source: https://habr.com/ru/post/1764337/


All Articles